cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

Using assigned variable in apply to each NOT working Screenshots

Hello everyone,

maybe somebody has a solution or can tell me if this is a bug or not. This is my scenario:

 

I am getting items from a SP list based on a filter. The read values are evaluated in an apply to each. A switch is used to determine the column and based on that a value form the list is assigned to a variable or sometimes a calculation is done and the result is then assigned to the variable. 

The Problem:

The first run with the first value is correct. In the second value everything is correct except the variable. Even though it is assigned the correct value to the variable, when I create an item in this apply-to-each, the value from the variable is the value form the first variable. 

Screenshots:

Flow starts on selected item and gets items based on a filter (always more than 1)Flow starts on selected item and gets items based on a filter (always more than 1)apply to each value is from body get items. the switch is visible in the next screenshot. It has all together 11 cases.apply to each value is from body get items. the switch is visible in the next screenshot. It has all together 11 cases.Each case either assigns value form body (get_items) or has a calculation and assigns the value. The variable used is always the same: floatRechnungsnummerBetrag. (german)Each case either assigns value form body (get_items) or has a calculation and assigns the value. The variable used is always the same: floatRechnungsnummerBetrag. (german)Another condition, switch and two more conditions before it gets down to REST, JSON, and then creating item.Another condition, switch and two more conditions before it gets down to REST, JSON, and then creating item.The variable at the bottom, (at the top is currently always a one) is: valriables('floatRechnungsnummerbetragNetto') . this is the problem here.The variable at the bottom, (at the top is currently always a one) is: valriables('floatRechnungsnummerbetragNetto') . this is the problem here.

Check after the run from 2nd value body(get_items), with the correct value of 499.Check after the run from 2nd value body(get_items), with the correct value of 499.BUT during creation of send element from second body(get_items) value, the variable shows 6660, which is the variable from the first run.BUT during creation of send element from second body(get_items) value, the variable shows 6660, which is the variable from the first run.

Any help or input is greatly appreciated. 

Patrizia

5 REPLIES 5
Highlighted
Community Support
Community Support

Re: Using assigned variable in apply to each NOT working Screenshots

Hi @Solara79,

 

I noticed that the four actions in Apply_to_each seem to be independent, so how do you configure "Set variable 4"?

If you set the same value for the variable in "Set variable 4", then the value of the variable will be the same for each execution of Apply_to_each.

I want to know which branch of the "Create item" action is configured, or after which conditions are met, the action is executed.

I am thinking that the value stored in the variable is not what you expected, probably because the value of the variable has been rolled back to the value set for the first time in the configuration of a step.

The value of a variable is always changing, depending on the context in which it is located and the context in which the action is used.

Which may involve the step of reassigning, which will change the value of the variable and act on the action below the same branch.

 

Best Regards,

Barry

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Frequent Visitor

Re: Using assigned variable in apply to each NOT working Screenshots

Hi  v-bacao-msft,

"set variable 4" was a random help variable, which is not used in this context. 

 

I know what you mean with : "I am thinking that the value stored in the variable is not what you expected, probably because the value of the variable has been rolled back to the value set for the first time in the configuration of a step."

But the variable is set inside the "apply-to-each", based on a column which changes in "apply-to-each." I have the switch, that checks the value from "apply-to-each" and assigns the correct information to the variable, which should be then used, as it is not changing in that loop. It changes again in the next loop, the next value from "apply-to-each".

 

I took screenshots from a run:

Apply2Each: 2 items are inside, delay is 4 sec, does not have to be in, as I was trying to find the cause. First condition no influence. In the Switch is where the variable is set, so each time a value is found, here 2 times.Apply2Each: 2 items are inside, delay is 4 sec, does not have to be in, as I was trying to find the cause. First condition no influence. In the Switch is where the variable is set, so each time a value is found, here 2 times.Switch: takes the value from a column from the get_item (in apply_to_each), checks it and based on the value assigns a number or value from get_item to the variable.Switch: takes the value from a column from the get_item (in apply_to_each), checks it and based on the value assigns a number or value from get_item to the variable.Other conditions are being checked.Other conditions are being checked.4.JPGIn this "Create OffenePosten for Invoice 1" is the variable. In this screenshot it's the value from the get_items inside apply_to_each. Which is 6660.In this "Create OffenePosten for Invoice 1" is the variable. In this screenshot it's the value from the get_items inside apply_to_each. Which is 6660.Here you see the assigned value in the 1st run is correct 6660.Here you see the assigned value in the 1st run is correct 6660.Second value assigned to the variable is also correct, a 499., that's the second run (2nd value form get_items in apply_to_each)Second value assigned to the variable is also correct, a 499., that's the second run (2nd value form get_items in apply_to_each)BUT: when the variable is accessed in the same run, the 2nd. it takes the first value, even though we are in the second run of apply_to_each, and further up the variable has the correct amount set. see above. That's the whole weird thing.BUT: when the variable is accessed in the same run, the 2nd. it takes the first value, even though we are in the second run of apply_to_each, and further up the variable has the correct amount set. see above. That's the whole weird thing. 

Highlighted
Regular Visitor

Re: Using assigned variable in apply to each NOT working Screenshots

Hi , Is your flow working fine now,If yes,kindly share what workaround you made.Im also facing issue.

Highlighted
New Member

Re: Using assigned variable in apply to each NOT working Screenshots

@v-bacao-msft 

 

could you please let me know the feasible solution for this of how to change variable value from the fixed as mentioned in your reply to as per the for each loop.

 

i am using 4 for each loops and in the second for each loop i have set the variable. while seeing the data its resetting back as you said to the first value.

 

could you please let me know what is the solution for this

 

@Solara79 

@XyZt 

@PowerAutomate 

@powerautomate1 

Highlighted
Helper I
Helper I

Re: Using assigned variable in apply to each NOT working Screenshots

Hi @XyZt 

 

i found the solution for this . please disable the concurrency control if there are any variables used in your flow and multiple for each loops are used.

 

 

Helpful resources

Announcements
Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

Upcoming Events

Experience what’s next for Power Automate

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

Community Conference

Power Platform Community Conference

Find your favorite faces from the community presenting at the Power Platform Community Conference!

Top Solution Authors
Top Kudoed Authors
Users online (6,501)