cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper III
Helper III

Using if expressions in flow

Hello Guys, 

 

I am trying to auto mate a process such that two fields in a list are inputs from a flow copies the fields from another list and creates or updates this list B.  one field from list A is category and another is name. i want to add a flow to list B such that as the field is copied from list A and the category is "C1" it would auto populate another field for that same item in list B with value of 30 , else if it is C2 it should populate with 25   C3--- 20, C4--15, C5-- 10 . i want to use the if expression in flow or any other means to achieve this would be highly appreciated.

Thanks in advance for your response guys.

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Dual Super User III
Dual Super User III

Re: Using if expressions in flow

@abieba 

I have implemented a simulation of your flow by using a string variable called RandomCategory instead of triggerBody()?['Category']?['value'] and the execution succeeded.

 

Flow_nested_array_2.png

 

So, I guess the problem is when evaluating triggerBody()?['Category']?['value']. Can you add a Compose action block just before your second Condition, add triggerBody()?['Category']?['value'], reexecute the flow and verify its content?

Hope this helps

 



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



View solution in original post

10 REPLIES 10
Highlighted
Super User II
Super User II

Re: Using if expressions in flow

You would Add a condition(s) to a flow. You can use expressions in conditions to check multiple values, and if you need more information about logical expressions, see the A Visual Explanation of Flow Logical Expressions (blog post).

If you could provide an expanded screenshot of your Flow and steps we could likely better assist you.

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

 

Highlighted
Helper III
Helper III

Re: Using if expressions in flow


Thank @Brad_Groux  4 your swi4t response this is the 4low that does the copy and updating 4rom list A to list B 
can i add the i4 expression in this 4low to a44ect the created or updated output.

 

pic 1.PNGpic 2.PNG

Highlighted
Dual Super User III
Dual Super User III

Re: Using if expressions in flow

@abieba 

So in your Create Item action block you need to fill the "Annual leave allocated" with:

value 30 if "Category" value is C1

Value 25 if  "Category" value is C2

Value 20 if  "Category" value is C3

Value 15 if  "Category" value is C4

Value 10 if  "Category" value is C5

And "Annual leave allocated" column on your sharepoint list is of type Integer, right?

 

If so, I would suggest you to:

Step#1: just before your condition action block, create an array variable with the following pairs:

[['C1','30'],['C2','25'],['C3','20'],['C4','15'],['C5','10']]

I have used the following expression for such purpose:

createArray(createArray('C1','30'),createArray('C2','25'),createArray('C3','20'),createArray('C4','15'),createArray('C5','10'))
flow_nested_array.png

Step#2: Add a new Apply to Each inside the 'true' branch of your condition, using the variable you created as its input

Step#3: Include a condition inside the Apply to each, so you compare if triggerBody()?['Category']?['value'] is equal to first(item()). If true, then invoke "Create item action block" using int(last(item())) as the input for "Annual leave allocated". Leave the 'false' branch empty

In the future, if more categories are added, then you just need to update the variable

Hope this helps

 

 

 



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Highlighted
Helper III
Helper III

Re: Using if expressions in flow

Hello @efialttes ,

Thank you 4or your swi4t response.

i have tried what you mentioned please see picture to con4irm. pic 2.PNG

 

i ran it and had this error.

 

pic 1.PNG

Highlighted
Dual Super User III
Dual Super User III

Re: Using if expressions in flow

@abieba 

I have implemented a simulation of your flow by using a string variable called RandomCategory instead of triggerBody()?['Category']?['value'] and the execution succeeded.

 

Flow_nested_array_2.png

 

So, I guess the problem is when evaluating triggerBody()?['Category']?['value']. Can you add a Compose action block just before your second Condition, add triggerBody()?['Category']?['value'], reexecute the flow and verify its content?

Hope this helps

 



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



View solution in original post

Highlighted
Dual Super User III
Dual Super User III

Re: Using if expressions in flow

Hi again

Please remember to inspect all iterations of the Apply to Each loop to identify which one failed:

Flow_nested_array_3.png



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Highlighted
Helper III
Helper III

Re: Using if expressions in flow

Thank you @efialttes , adding the compose 4unction worked well,

can you please explain the 4low and how those things you added works, i am actually new to these and am a bit con4used, yes it worked but i want to understand why and how.

 

 

Highlighted
Dual Super User III
Dual Super User III

Re: Using if expressions in flow

@abieba 

Wow! I just suggested to add the compose action block for troubleshooting purposes, so it is unclear to me why it is working now and failed before

The Apply to each you added iterates over the array variable. So in its first execution it takes the first element from the array: ['C1','30'], the second time it takes the second element from the array: ['C2','25'], and so and so. Please note each element is also an array.

 

In its first execution the expression first(item()) extracts the first element from ['C1','30'] : the result is the string 'C1'. In its second execution the expression first(item()) extracts the first element from ['C2','25'] : the result is the string 'C2'. And so and so.

 

In its first execution the expression last(item()) extracts the first element from ['C1','30'] : the result is the string '30'. In its second execution the expression last(item()) extracts the first element from ['C2','25'] : the result is the string '25'. And so and so. The expression int(last(item()) converts the string into an integer.

 

Hope this helps



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Highlighted
Helper III
Helper III

Re: Using if expressions in flow

Hello @efialttes ,

 

Seems i am running into a bit o4 trouble,

 

a4ter the 1st addition others are coming out in multiples.

Capture.PNG

and its takes a while b4 it actually comes in too.

 

Highlighted
Helper III
Helper III

Re: Using if expressions in flow

Hello @efialttes , 

 

I have seen the problem, i had another 4low causing the problem, thanks

so in addition to that 4low, how can i add another array to select '90' if  sex is female and select '10' if male in the maternity/paternity 4ield. 

i.e having multiple arrays b4 item is created.

Helpful resources

Announcements
firstImage

Super User Program Update

Three Super User rank tiers have been launched!

firstImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

Users online (7,579)