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

Is there a possibility of having a local variable or anything close to a local variable?

I am trying extract information from object dynamically based on a {variableName} i.e. "Material Information 1", "Material Information 2" ... "Material Information {variableName}"
At the end of each loop, variableName will be variableName+1

 

The concurrent in 'Apply to Each' is registering the global variable {variableName} so some actions are affected by the variable.

 

Is there a possibility of having a local variable to the loop or anything close to a local variable?
so that when we are performing any action on it, it would execute properly on each input in apply to each.

1 ACCEPTED SOLUTION

Accepted Solutions

Ah, I see what you mean now. Yeah, in that case you have two choices for handling this:

  • Set the max concurrency for the Apply To Each to 1 (screenshot below)
    cchannon_0-1634157023516.png

     

  • Create your loop as a child flow and call it from the flow you're in. That will let you initialize a loop-specific var inside the child flow.

 

View solution in original post

4 REPLIES 4
cchannon
Super User
Super User

In PowerAutomate, You can only declare variables outside loops, but then you can manipulate them within the loop. So just add an "Initialize a Variable" step outside your loop to create the var, then handle its value inside the loop, including a value initialization at the start of each loop and it will operate just as though it was declared within the loop. Something like: 

 

  • Initialize Var "myVar" == "initialized";
  • Apply To Each:
    • Set Variable Value "myVar" = "";
    • Do stuff
Jhmiah
Frequent Visitor

Thanks for the reply. However, I believe that when we set variable, it is changing the global variable which will interfere with the other concurrent operations.
i.e.
lets say there are n=50 concurrency, inside Apply to each (n=1), there is a 'Do Until' that references x(x=1). At the end of 'Do Until', there will be a increment variable (x=x+1), so NOW x=2.
because of latency, lets say n=14 is running later, inside apply to each (n=1), it is using the global variable x=2 that was set by ApplyToEach(n=1). Therefore it skipped n=1.

 

Is this a limitation in Power Automate?

Ah, I see what you mean now. Yeah, in that case you have two choices for handling this:

  • Set the max concurrency for the Apply To Each to 1 (screenshot below)
    cchannon_0-1634157023516.png

     

  • Create your loop as a child flow and call it from the flow you're in. That will let you initialize a loop-specific var inside the child flow.

 

rajyraman
MVP

@Jhmiah- If all you need is an iteration variable that increments by one after every iteration, you can use iterationIndexes. Along with concurrency of 20, it will give you better performance.

 

https://docs.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference#i...

 

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Users online (1,958)