0

I'm trying to look for specific keywords inside of text from a for each loop.

var text = "The lazy fox jumped over the brown dog."
var keywords = "fox,dog,sun";

If true, I want to do something with the text. If false, I want to ignore the text.

Does anyone know how to use an Array filter, Function, Select, Condition or inline code to check for this? If so, specific examples would be great.

By the way, I have a C# function that handles this extremely well in an ASP.net Core app.

UPDATE 1:

This doesn't work.

enter image description here

UPDATE 2:

The Condition is always false after the for each loop even after changing the settings and parallelism to 1.

Azure Logic App Condition does not work in loop if based on changing values

Thanks in advance!

3 Answers 3

2

There are so many ways to achieve what you need. Here are the 3 options that came to my mind within a minute.

  1. The first one does use a For each loop, but I wouldn't recommend using it as it's not very efficient.

enter image description here

The For each parameter looks like this:

enter image description here

The Condition parameter looks like this:

enter image description here

  1. The second option is much easier - no need for a loop, just filter the array straight away, then you can check whether it's empty or it has some items:

enter image description here

The Filter array parameters look as follows.

enter image description here

The split function is identical to the one used in option 1.

  1. If you know JavaScript, you might decide to use regular expressions in inline code instead, e.g.:

enter image description here

Then you'd just need to check the output of the inline code. JavaScript code used in the example above:

var text = workflowContext.actions.Compose_text.outputs;
var keywords = workflowContext.actions.Compose_keywords.outputs;
return text.match(new RegExp("(" + keywords.split(",").join("|") + ")", "gi"));

My personal preference is option 2. However, please note that all 3 options above would find "sun" in text "The weather was sunny" even though there's no word "sun" in the text. If you do need "sun" to match only word "sun" - not "sunny", "asunder" or "unsung" - then go for option 3, just use a different, more complex regular expression.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks @10p! Unfortunately, none of this will really work for me. My best shot was inline code, but according to the Documentation it doesn't support loops or variables. learn.microsoft.com/en-us/azure/logic-apps/… I'm checking for specific words (list of words) within a for each loop. If I find the word in the text, I do something.
Can you please clarify, why exactly wouldn't this work for you? You can use output of Compose actions instead of variables in inline code, like I did above in option 3. I actually thought of a way to check for specific words in option 2 as well. But if you prefer option 3 and you know JavaScript, I don't think you are going to have any issue (only the size of JavaScript code used in Logic Apps is limited).
1

One of the workaround would be use of Condition Connector. I have initialized the sentence in a string and then used Condition Connector which will be checking the conditions. enter image description here

Finally, In the true section you can add the connectors accordingly.

2 Comments

Thanks @SwethaKandikonda-MT! Can I build the Condition using a for each loop? If not, how do I create this? The keywords will be different for each Workflow I create. The Workflows will be created programatically.
Please see Update 1 @SwethaKandikonda-MT!. I can't get anything to work.
0

Placing a Compose behind the for each loop and referencing the Output in the Condition is what finally worked for me. I used the toLower() function in my Compose. The Compose looks like this.

toLower(items('For_each_2')?['day']?['longPhrase'])

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.