cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
FernandB
Helper II
Helper II

Condition based on multi select column

Hello,

 

I would like to create a condition on a multi select field to NOT send an email when "Value Other" is  the only value selected but if other values are selected along with "Value Other" then I would like to send the email, unfortunately this is not the case.

 

Value 1

Value 2

Value 3

Value Other

 

I have an Appended String Variable  for a semicolon as a delimiter. How would I accomplish this in the condition?

 

Thank you Fernand

1 ACCEPTED SOLUTION

Accepted Solutions
Paulie78
Super User III
Super User III

ok, I had a look, the expression I gave you is not reliable with your delimited string. So you are going to have to make a couple of modifications (This would not be required if you used an array instead of a delimited string, but this will work, take a look at this:

https://ibb.co/n0TH4Yh

Symptoms.png

Explanation:

The reason it did not work before, is that the input was slightly unreliable (had spaces etc in in and was returning empty array elements.

Example:

Using variable value " New or worsening cough;  Other; "

 

Step 1 - Split String - The string is split on a semi colon and that produces this array:

 

 

[
  " New or worsening cough",
  "  Other",
  " "
]

 

 

You can see there is an empty element, and the other elements contain some spacing. Code is:

split(variables('mutliSelectValue'), ';')

 

Step 2 - Select  - The select in text mode action cleans up the output a bit by trimming the results. The array is now:

 

 

[
  "New or worsening cough",
  "Other",
  ""
]

 

 

Code is:

trim(item())

Step 3 - Filter - The empty results are removed. The array is now:

 

[
  "New or worsening cough",
  "Other"
]

 

The array output is now sensible and we can do run an expression on it in a reliable way.

Step 4 - Condition

Condition is modified, new version works from the filter output and is like this:

concat
(
  if
  (
    and
	(
	  equals(length(body('Filter_array')), 1),
	  contains(body('Filter_array'), 'Other')
	),
	'noEmail',
	''
  ),
  if
   (
     and
     (
       greater(length(body('Filter_array')), 1),
	   contains(body('Filter_array'), 'Other')
     ),
     'sendEmail',
     ''
  )
)

View solution in original post

31 REPLIES 31
Paulie78
Super User III
Super User III

concat
(
  if
  (
    and
	(
	  equals(length(split(variables('mutliSelectValue'), ';')), 1),
	  contains(variables('mutliSelectValue'), 'Value Other')
	),
	'noEmail',
	''
  ),
  if
   (
     and
     (
       greater(length(split(variables('mutliSelectValue'), ';')), 1),
	   contains(variables('mutliSelectValue'), 'Value Other')
     ),
     'sendEmail',
     ''
  )
)

In this example the variable holding the variable is called multiSelectValue

First if expression checks if it contains Value Other and the number of values in the delimited string is equal to 1 and outputs "noEmail"

Second if expression check if it contains Value Other and the number of values in the delimited string is greater than 1 (i.e. it contained something else in addition to Value Other) and outputs "sendEmail".

 

Hope this helps.

Hi Paulie,

 

Thank you very  much for your response. Where in my flow would I place this? This is what I have so far.

FernandB_0-1614350391710.png

 

Paulie78
Super User III
Super User III

Put the expression on the left side of your condition, the operator should be equal to, the right hand side should be sendEmail.

Like this?

 

FernandB_0-1614358129726.png

 

Paulie78
Super User III
Super User III

Yep

FernandB
Helper II
Helper II

It didn't work with "Other" selected or not.

 

FernandB_1-1614362068819.png

 

Paulie78
Super User III
Super User III

Put the expression into a compose action before the condition, so you can see what the output is.

FernandB
Helper II
Helper II

How do I see the Output. This is what I have now.

FernandB_0-1614362783589.png

 

Paulie78
Super User III
Super User III

Run the flow, and when it runs it will show you what output the compose action produced. You could also add another compose action right before that one and put your array in there. That way we would get to see the content of the array and the output of the expression at the same time.

FernandB
Helper II
Helper II

Al I get is "" in the output. When you say array are you talking about the Append to String?

When adding the 2nd Compose with the I got the following output/input:

" New or worsening cough;  Other; "
 
This should have allowed the email to send but the condition result was false instead of true.
Paulie78
Super User III
Super User III

Ok, I see the problem. Will come back to you shortly - not with a computer right now.

FernandB
Helper II
Helper II

Thank you!

I changed Value Other to Other, sorry about that. When I select Other by itself or with other Symptoms the Compose result is "sendEmail" and when I select a Symptom I get 

{
    "expressionResult"false
}
Paulie78
Super User III
Super User III

ok, I had a look, the expression I gave you is not reliable with your delimited string. So you are going to have to make a couple of modifications (This would not be required if you used an array instead of a delimited string, but this will work, take a look at this:

https://ibb.co/n0TH4Yh

Symptoms.png

Explanation:

The reason it did not work before, is that the input was slightly unreliable (had spaces etc in in and was returning empty array elements.

Example:

Using variable value " New or worsening cough;  Other; "

 

Step 1 - Split String - The string is split on a semi colon and that produces this array:

 

 

[
  " New or worsening cough",
  "  Other",
  " "
]

 

 

You can see there is an empty element, and the other elements contain some spacing. Code is:

split(variables('mutliSelectValue'), ';')

 

Step 2 - Select  - The select in text mode action cleans up the output a bit by trimming the results. The array is now:

 

 

[
  "New or worsening cough",
  "Other",
  ""
]

 

 

Code is:

trim(item())

Step 3 - Filter - The empty results are removed. The array is now:

 

[
  "New or worsening cough",
  "Other"
]

 

The array output is now sensible and we can do run an expression on it in a reliable way.

Step 4 - Condition

Condition is modified, new version works from the filter output and is like this:

concat
(
  if
  (
    and
	(
	  equals(length(body('Filter_array')), 1),
	  contains(body('Filter_array'), 'Other')
	),
	'noEmail',
	''
  ),
  if
   (
     and
     (
       greater(length(body('Filter_array')), 1),
	   contains(body('Filter_array'), 'Other')
     ),
     'sendEmail',
     ''
  )
)

View solution in original post

Thank you so much for this and the explanation! I got the following error unfortunately.

 

The execution of template action 'Filter_array' failed: The evaluation of 'query' action 'where' expression '@greater(length(item()), 0)' failed: 'The template language function 'length' expects its parameter to be an array or a string. The provided value is of type 'Object'. Please see https://aka.ms/logicexpressions#length for usage details.'.

FernandB_0-1614447827459.png

 

 

FernandB
Helper II
Helper II

In the Filter array my Output is coming from the Select

Paulie78
Super User III
Super User III

Go into the run history and post the output of your select. I suspect your select was not in "text mode". Which you achieve by pressing this little button:

Paulie78_0-1614449462879.png

 

FernandB
Helper II
Helper II

Input:

[
  "Other",
  " Other",
  ""
]
 
Output:
 
[
  {
    "Other"""
  },
  {
    "Other"""
  },
  {
    """"
  }
]

Helpful resources

Announcements
MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MSFTBizAppsLaunchEvent

Experience what’s next for Power Virtual Agents

See the latest Power Automate innovations, updates, and demos from the Microsoft Business Applications Launch Event.

New Super Users

Meet the Power Automate Super Users!

Many congratulations to the Season 1 2021 Flownaut Crew!

Power Platform ISV STudio

Power Platform ISV Studio

ISV Studio is the go-to Power Platform destination for ISV’s to monitor & manage applications post-AppSource publish.

Users online (12,215)