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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Persistent values of v...
Power Automate
Answered

Persistent values of variables within a For each cycle

(1) ShareShare
ReportReport
Posted on by 15

Good day, everyone,

 

Particularly in my case, I currently have a flow in which within a For Each cycle the value of two variables is updated by assigning them a property of the items() entity, that is, the element of the iteration.

 

At this moment a strange behavior is happening since these variables are not taking the new value that they are being assigned but retain the value they had in the previous iteration of the cycle, an adjustment was made so that at the beginning of the iteration of the cycle empty values were assigned to these variables in order to "clean" the data they had previously.

 

This adjustment was not effective since the previous value of the variable persists, as if it were a type of memory chaché of the variables.

 

Please could you help me in this particular case, as I hadn't previously had this kind of behavior on variables.

 

Categories:
I have the same question (0)
  • abm abm Profile Picture
    32,985 Most Valuable Professional on at

    Hi @Cesar_Developer 

     

    Could you please post a screenshot of your flow?

     

    Thanks

  • Cesar_Developer Profile Picture
    15 on at

    Hi @abm, thanks for your reply,

     

    A more precise description is the following:

     

    There is a variable called a numeroFacturaRegistro of type string which is declared or initialized with an empty value

     

    Cesar_Developer_0-1652810434568.png

     

    Later we have an array of objects, like this:

    Cesar_Developer_1-1652810460131.png

     

    Within which for each object of the array you have a property called "Factura" (A reference is made later on this property)

     

    It is necessary to make a cycle that runs through this array of objects to send emails, within this cycle initially the current item is shown in a compose action. We can see that for iteration 1, this property has the value "FE 31".

     

    Cesar_Developer_2-1652810497534.png

     

    After this, the variable numeroFacturaRegistro is cleaned

    Cesar_Developer_3-1652810534198.png

     

    Later the value of "factura", that is "FE 31", is saved in this variable


    Edition mode of the action:

    Cesar_Developer_4-1652810607460.png

     

    Execution mode of the action:

    Cesar_Developer_5-1652810628193.png

     

    After this, by means of a compose action it is verified what the real value of the variable is:

     

    Edition:

     

    Cesar_Developer_12-1652810913594.png

    Execution:

     

    Cesar_Developer_8-1652810696134.png

     

    Later, this data is taken into account to send an email to a customer. 

     

    Until this first iteration of the For Each cycle, everything goes according to the flow without problem.


    The problem occurs in the next iteration (No. 2).

     

    Starting again by referencing the current value of the current item in the cycle, you can see that now Invoice has the value of "FE 37":

    Cesar_Developer_9-1652810770210.png

    Then, again the variable numeroFacturaRegistro is emptied

    Cesar_Developer_10-1652810798154.png

    And then it is assigned the value of the "factura" property located on the current object in the cycle:

     

    Cesar_Developer_11-1652810856526.png

     

    Apparently up to this point the variable numeroFacturaregistro has the value "FE 37", but when arriving at the compose action, in which direct reference is made to the variable, the value that actually stored the variable is shown, which was the one it had in iteration 1 of the cycle:

     

    Edition:

    Cesar_Developer_12-1652810913594.png

    Execution:

     

    Cesar_Developer_13-1652811130969.png

     

    It is really confusing since no error is shown when assigning values to the variable.

     

     

    Greetings.

  • abm abm Profile Picture
    32,985 Most Valuable Professional on at

    Hi @Cesar_Developer 

     

    Where you emptied the variable numeroFacturaRegistro ? Is this inside the loop?

     

    Thanks

  • Cesar_Developer Profile Picture
    15 on at

    Yes, it is inside the loop.

  • Verified answer
    abm abm Profile Picture
    32,985 Most Valuable Professional on at

    Hi @Cesar_Developer 

     

    Try the below and let me know the result. Set the apply to each setting like below.

     

    image.png

  • Cesar_Developer Profile Picture
    15 on at

    Thank you for your response.

     

    I was busy, but your solution worked for me.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 796

#2
Valantis Profile Picture

Valantis 568

#3
Haque Profile Picture

Haque 538

Last 30 days Overall leaderboard