How to check more than one word contains in string

Hello,

my requirement is we have automated jira tikcets where automation fetches using API and work on it if Jira ticket summary is like below (fetching using API in string variable_
summary - Please activate the Jira license & confluence for below user

if summary contans any word(one or more) from this list - Workflows, Screens, Boards, Dashboards, Fields, Permissions, Notifications, Priorities, Reports/Gadgets, Big Picture, EazyBI, Exalate, GIT, Tempo TimeSheets, Time to SLA, X-Ray

one more thing users may write above words in capital as well so tell me accordingly

then i need to send notification that i will manage.
but how can i check if summary contains any word from above list
is there any LINQ query?

can you help me with it or other approch?

Hi @Mathkar_kunal

Yes, you can use a LINQ - it’s going to be a long one lol but it can work.

I would first create an array that holds all of those keywords that you mentioned, then in an assign you create a Boolean named “containsKeyword” as an example. And finally you can do something like this in an assign:

matchedKeyword = (New String() {
“Workflows”, “Screens”, “Boards”, “Dashboards”, “Fields”,
“Permissions”, “Notifications”, “Priorities”, “Reports/Gadgets”,
“Big Picture”, “EazyBI”, “Exalate”, “GIT”, “Tempo TimeSheets”,
“Time to SLA”, “X-Ray”
}).FirstOrDefault(Function(keyword) summary.IndexOf(keyword, StringComparison.OrdinalIgnoreCase) >= 0)

Then you can simply use an IF condition to check if containsKeyword = True

The best thing is to rather create that array as a String Asset in Orchestrator (and then split it by a character into an array) - because you can modify it at any point without making a code change. Safest approach.

You can also use regular expressions to do it. Pretty much a similar concept except you’re matching the word in an expression rather than a LINQ:

containsKeyword = System.Text.RegularExpressions.Regex.IsMatch(
summary,
“Workflows|Screens|Boards|Dashboards|EazyBI|GIT”,
System.Text.RegularExpressions.RegexOptions.IgnoreCase
)

@Mathkar_kunal

Lets assume
your list of values stored in lstVar
and user given word is strUserword

Now the linq is
lstVar.Any(Function(x) strUserWord.Tolower.contains.(x.Tolower))

Hope it helps,
YK

Hi @Mathkar_kunal

Please check the below thread for your reference. It might help you

Regards,
Pravallika

Hi @Mathkar_kunal

Store Workflows, Screens, Boards, Dashboards, Fields, Permissions, Notifications, Priorities, Reports/Gadgets, Big Picture, EazyBI, Exalate, GIT, Tempo TimeSheets, Time to SLA, X-Ray in asset as a text.

Use Get Asset to read the particular asset in a variable say strSummaryWords.

After that use the below syntax to change it to list variable.
lstSmmaryWords = strSummaryWords.Split(","c).Select(Function(w) w.Trim()).ToList()
summary = Output of API

After use the below syntax in If:

If lstSmmaryWords.Any(Function(word) summary.IndexOf(word, StringComparison.OrdinalIgnoreCase) >= 0)
Then
    Send notification I will manage
Else
    Log Message
End If

Hope it helps!!
Parvathy

i need to store this words in config file because in case if any word i need to add then i can directlyt add in config file no need to chnage in script
but when i am assigning config variable to array string variable it is showing cannot assign system.char to system.string

keyword is array variable
and in config file i am providing same as i provided initially directly in assign

how can i convert config variable to array sting?
@yedukondaluaregala

Hi @Mathkar_kunal

Keywords = in_Config("FlaggedSummaryKeywords").ToString.Split(","c).Select(Function(w) w.Trim()).ToArray()

Regards
PS Parvathy

Hi @Mathkar_kunal

Yes, you can handle this easily using LINQ with case-insensitive check.

keywords = {“Workflows”,“Screens”,“Boards”,“Dashboards”,“Fields”,“Permissions”,“Notifications”,“Priorities”,“Reports”,“Gadgets”,“Big Picture”,“EazyBI”,“Exalate”,“GIT”,“Tempo TimeSheets”,“Time to SLA”,“X-Ray”}

result = keywords.Any(Function(k) summary.ToLower.Contains(k.ToLower))