Can't get Logic App Contains to work with array or comma separated string - azure-logic-apps

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.
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!

There are so many ways to achieve what you need. Here are the 3 options that came to my mind within a minute.
The first one does use a For each loop, but I wouldn't recommend using it as it's not very efficient.
The For each parameter looks like this:
The Condition parameter looks like this:
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:
The Filter array parameters look as follows.
The split function is identical to the one used in option 1.
If you know JavaScript, you might decide to use regular expressions in inline code instead, e.g.:
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.

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.
Finally, In the true section you can add the connectors accordingly.

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'])

Related

Filter Result Array from Loop in Power-Automate

I loop thru a lot of data in an array to filter it. I the example I only have one Supplier_ID to filter, in real life it would be a lot of.
As result I like to have one big array with all needed Supplier_IDs. This works fine.
But:
How can I avoid the "body": 'part / item' in the output of my COMPOSE (in German 'Verfassen') step?
Now I solved the union of the arrays inside the loop.
Please use expression
outputs('Filter_relevante_SupplierItems')?['body']
instead of
outputs('Filter_relevante_SupplierItems')
in the Verfassen step.
=============================Update============================
Have a try with expression: outputs('Filter_relevante_SupplierItems')[0]?['body']
=============================Update 2============================
Summarize from the chat room for other communities reference:
OP uses union() method to union two arrays in loop to solve the problem.
Another solution for others reference: we can also use replace() method to replace {"body":[ with empty string, replace(outputs(...), '{"body":[', ''). And then replace ]} with empty string, replace(outputs(...), ']}', ''). It can also remove the body.

regex with OR condition not working in angularjs [duplicate]

I'm creating a javascript regex to match queries in a search engine string. I am having a problem with alternation. I have the following regex:
.*baidu.com.*[/?].*wd{1}=
I want to be able to match strings that have the string 'word' or 'qw' in addition to 'wd', but everything I try is unsuccessful. I thought I would be able to do something like the following:
.*baidu.com.*[/?].*[wd|word|qw]{1}=
but it does not seem to work.
replace [wd|word|qw] with (wd|word|qw) or (?:wd|word|qw).
[] denotes character sets, () denotes logical groupings.
Your expression:
.*baidu.com.*[/?].*[wd|word|qw]{1}=
does need a few changes, including [wd|word|qw] to (wd|word|qw) and getting rid of the redundant {1}, like so:
.*baidu.com.*[/?].*(wd|word|qw)=
But you also need to understand that the first part of your expression (.*baidu.com.*[/?].*) will match baidu.com hello what spelling/handle????????? or hbaidu-com/ or even something like lkas----jhdf lkja$##!3hdsfbaidugcomlaksjhdf.[($?lakshf, because the dot (.) matches any character except newlines... to match a literal dot, you have to escape it with a backslash (like \.)
There are several approaches you could take to match things in a URL, but we could help you more if you tell us what you are trying to do or accomplish - perhaps regex is not the best solution or (EDIT) only part of the best solution?

Q: How to handle more than one condition in a UML state machine transition

How do I handle more than one condition (with different boolean expressions) in a UML state machine transition (as guard)?
Example:
In this example I would like to add more than only one condition (Tries < 3) in the transition from "logging in" to "Logged In" like discribed in the note.
How to handle this UML compliant?
Simply spoken (and to focus on the needed step)
put a boolean condition like above in the Guard. This can be any text. You can write C-style or plain text. I'm not sure about OCL here, but that's for academic purpose anyway (my opinion).
N.B. Your diagram shows Tries = 3 which should be a Guard also (i.e. [Tries = 3]) rather than a Name.
There are a couple of options here:
Your guard condition can combine multiple checks within the '[]' - much like you were doing in the note.
You can have multiple transitions between the same two states, each with its own condition.
You can have states within states. So in your example the three states could be within a superstate of 'Normal Operation' - which you then further define in other documentation or via a note.
All of these are valid UML syntax. But note that just because something is valid doesn't mean it will be supported in your editor. For example it was many years before most of the features of sequence diagrams became available within editors...

Angular NgTagsInputs - RegEx - Allow all values expect Strings

I'm using ngTagsInput where I want to allow all tags expect a few strings.
In their documentation it appears I can specify allowed tags through a regex but I can seem to work it out - been trying http://regexr.com/ for last hour with no luck.
So for example the strings I dont want to be accepted are:
story and global.
How do i go about to say everything is allowed expect those 2?
So for example storyBreaking is allowed but story is not.
Thanks.
try something like that:
(?<![\w\d])abc(?![\w\d]) where abc is your string to match!

ibatis dynamic sql using two conditions

I would like to use a dynamic sql statement that executes only when the variable is not null AND greater than zero. Like this:
<isNotNull prepend="AND" property="ProprietaryId">
<isGreaterThan prepend="AND" property="ProprietaryId" compareValue="0">
G.PROPRIETARY_ID = #ProprietaryId#
</isGreaterThan>
</isNotNull>
but without prepending two 'AND's.
I have read the documentation but have found no good example.
To work around to this issue I almost never use the "prepend" feature, but instead write an sql like this:
WHERE 1=1
<isNotNull property="ProprietaryId">
<isGreaterThan property="ProprietaryId" compareValue="0">
AND G.PROPRIETARY_ID = #ProprietaryId#
</isGreaterThan>
</isNotNull>
I just came across this question while looking for the same answer. While effective, this solution kind of bugged me so I studied the iBATIS docs some more and noticed this example:
<dynamic prepend="where">
<isGreaterThan prepend="and" property="id" compareValue="0">
ACC_ID = #id#
</isGreaterThan>
<isNotNull prepend="and" property="lastName">
ACC_LAST_NAME = #lastName#
</isNotNull>
</dynamic>
You'd think that might cause a superfluous "and" to be included within the WHERE clause if only one of the conditions is true, but apparently iBATIS is smart enough to prevent this when using the dynamic tag. It works for me (using iBATIS 2.3.0 in this case).
Its me from the future. Parent elements override the prepend of their first child, so your code will work fine since the isGreaterThan prepend will be overwritten by the parent isNotNull prepend.
From the docs:
The prepend attribute is a part of the code that is free to be overridden by the a parent element's prepend if necessary. In the above example the "where" prepend will override the first true conditional prepend. This is necessary to ensure that the SQL statement is built properly. For example, in the case of the first true condition, there is no need for the AND, and in fact it would break the statement.
<isNotNull property="ProprietaryId">
<isGreaterThan prepend="AND" property="ProprietaryId" compareValue="0">
G.PROPRIETARY_ID = #ProprietaryId#
</isGreaterThan>
</isNotNull>
just delete the first prepend will work

Resources