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

Community site session details

Session Id : AxJcSzeEA66+NwEy8DtCaW
Power Automate - Building Flows
Answered

Clear array variable in a flow

Like (4) ShareShare
ReportReport
Posted on 13 Jan 2018 15:21:26 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? 

I have the same question (0)
  • Verified answer
    v-xida-msft Profile Picture
    on 16 Jan 2018 at 02:46:49
    Re: Clear array variable in a flow

    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 31 Jan 2018 at 15:25:06
    Re: Clear array variable in a flow

    Thanks for help.

  • Community Power Platform Member Profile Picture
    on 13 Feb 2019 at 00:59:27
    Re: Clear array variable in a flow

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

  • Community Power Platform Member Profile Picture
    on 05 Oct 2019 at 08:21:21
    Re: Clear array variable in a flow

    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 13 Apr 2020 at 16:10:13
    Re: Clear array variable in a flow

    Hi

     

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

     

    Thanks and Regards

    Vivek Verma

  • cbboatwr Profile Picture
    16 on 06 Dec 2020 at 22:34:38
    Re: Clear array variable in a flow

    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 30 Jun 2022 at 04:22:57
    Re: Clear array variable in a flow

    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 31 Mar 2023 at 20:33:00
    Re: Clear array variable in a flow

    @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 01 Mar 2024 at 13:03:48
    Re: Clear array variable in a flow

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

  • SureshPaul Profile Picture
    4 on 01 Mar 2024 at 13:07:33
    Re: Clear array variable in a flow

    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 788 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 452 Moderator

#3
developerAJ Profile Picture

developerAJ 302

Last 30 days Overall leaderboard
Loading complete