web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Clear array variable i...
Power Automate
Unanswered

Clear array variable in a flow

(4) ShareShare
ReportReport
Posted on by 22

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? 

Categories:
I have the same question (0)
  • Verified answer
    v-xida-msft Profile Picture
    on at

    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

     

     

  • Kamil Profile Picture
    22 on at

    Thanks for help.

  • Community Power Platform Member Profile Picture
    on at

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

  • Community Power Platform Member Profile Picture
    on at

    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?

  • VivekVerma Profile Picture
    10 on at

    Hi

     

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

     

    Thanks and Regards

    Vivek Verma

  • cbboatwr Profile Picture
    16 on at

    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

     

  • KashifZH Profile Picture
    35 on at

    You don't know how much that answer helped me! Thanks so much. This is such a common scenario as you'd want to reuse an array.

  • JohnNovember Profile Picture
    11 on at

    @Kamil Please consider marking this as the answer. At the end of the loop (before it resets), use "Set Variable" with "[]" as the value. Less steps and variables required.

     

    JohnNovember_0-1680294721415.png

     

  • SureshPaul Profile Picture
    4 on at

    You should use the "clear list" if it is a list variable (array) 

  • SureshPaul Profile Picture
    4 on at

    Please use clear list as in the below screen shot

     

    SureshPaul_0-1709298442595.png

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 538 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 405 Moderator

#3
abm abm Profile Picture

abm abm 252 Most Valuable Professional

Last 30 days Overall leaderboard