cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Kamil
Kudo Collector
Kudo Collector

Clear array variable in a flow

I have a working flow with for each loop. In loop i'm using array variable to build a list of item to send it in e-mail. In next loop i need to use the same variable, but I want to start adding to empty array. How to set array variable to be "blank new" for next iteration of loop? 

1 ACCEPTED SOLUTION

Accepted Solutions
v-xida-msft
Community Support
Community Support

Hi @Kamil,

 

Could you please share a screenshot of your flow's configuration?

Do you want to set the array variable to empty for next iteration of loop?

 

I think a empty array variable could achieve your needs, I have made a test on my side and please take a try with the following workaround:

  • Add a proper trigger, here I use Flow Button trigger.
  • Add a Variables-> "Initialize variable" action, Name set to GlobeArray, Typre set to Array and Value set to empty.
  • Add a "Get items" action, specify Site Address and List Name.
  • Add a "Apply to each" aciton, input parameter set to output of the "Get items" action. Within "Apply to each", add a "Append to array variable" action, Name choose GlobeArray, Value set to Due Time dynamic content of the "Get items" action.
  • Under "Apply to each" action, add a "Compose" action, Inputs set to GlobeArray variable.
  • Add a Variables-> "Initialize variable 2" action, Name set to EmptyArray, Type set to Array and Value set to empty.
  • Add a "Set variable" action, Name choose GlobeArray variable, Value set to EmptyArray variable.

Image reference:4.JPG

 

5.JPG

The flow works successfully as below:6.JPG

The value of GlobeArray variable after first iteration of loop as below:7.JPG

The value of GlobeArray variable after clearing array as below:8.JPG

Best regards,

Kris

 

 

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

View solution in original post

6 REPLIES 6
v-xida-msft
Community Support
Community Support

Hi @Kamil,

 

Could you please share a screenshot of your flow's configuration?

Do you want to set the array variable to empty for next iteration of loop?

 

I think a empty array variable could achieve your needs, I have made a test on my side and please take a try with the following workaround:

  • Add a proper trigger, here I use Flow Button trigger.
  • Add a Variables-> "Initialize variable" action, Name set to GlobeArray, Typre set to Array and Value set to empty.
  • Add a "Get items" action, specify Site Address and List Name.
  • Add a "Apply to each" aciton, input parameter set to output of the "Get items" action. Within "Apply to each", add a "Append to array variable" action, Name choose GlobeArray, Value set to Due Time dynamic content of the "Get items" action.
  • Under "Apply to each" action, add a "Compose" action, Inputs set to GlobeArray variable.
  • Add a Variables-> "Initialize variable 2" action, Name set to EmptyArray, Type set to Array and Value set to empty.
  • Add a "Set variable" action, Name choose GlobeArray variable, Value set to EmptyArray variable.

Image reference:4.JPG

 

5.JPG

The flow works successfully as below:6.JPG

The value of GlobeArray variable after first iteration of loop as below:7.JPG

The value of GlobeArray variable after clearing array as below:8.JPG

Best regards,

Kris

 

 

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

View solution in original post

Thanks for help.

Anonymous
Not applicable

You can also do a Set Variable with a value of null.

I have used the approach of setting the variable equal to null, however it stopped working about a week ago. Has the syntax of the "null" function changed?

Hi

 

You can just set variable to "[ ]" this will empty you

 

Thanks and Regards

Vivek Verma

cbboatwr
New Member

I'm not sure if the solution provided answer the user's question ... perhaps it did. But that shows how to reset an array after a loop as completed, as opposed to resetting for each iteration of the loop ... a scenario I think probably more common. Like if you were looping thru a list of managers and e-mailing that manager an array processed within the loop ... you'd want that array reset each time so one manager didn't get a cumulative listing of all preceding manager's info.

 

In this case, you still use the "Set variable" and set the variable's value to "[]" (empty array) WITHIN the lop ... however, you also have to set the loop's Concurrency Control. You need to turn it on and set the degree of parallelism to 1 ... this ensures the array is access by multiple parallel operations of the loop. You get to the settings by click the "..." and selecting "Settings" on the "Apply to each" control

 

cbboatwr_0-1607293913477.png

 

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Users online (1,075)