cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ScottRMeredith
Helper II
Helper II

Variable change without action

So this has been happening to me no matter how I try to attack the problem.  I have a list of employees (almost 16000 records) in a SP List(record of source).  I also have a pre-existing Model Driven App with dataverse tables with the same data and some more fields added.  What I am trying to accomplish is weekly run an flow that will compare the two lists and apply the changes in the SP list to the dataverse table and add any new records from the SP list to the dataverse table.  Fairly straightforward, but the problem I was having is in SP the employee number field was text, as well in dataverse (leading zeros), but for the life of me I couldn't get the query in the apply to each loop to find a matching record with the two fields as Single line of text fields.  So in the SP list I made it a number field.  This then dropped the leading zeros and created a new problem.  So I fixed this with a switch and length combination and got the flow to run fairly successfully once (24 records errored out of 15711).  I made some adjustments to try and account for the errors and the main problem I am having returned.  This is the 3rd iteration of a flow created from scratch so nothing was copied and pasted from previous flows that had the same problem could creep in from.  

 

So now that I have bored you to death, my problem is in my apply to each loop when I set my employee number variable, or just use the found record from the SP Get Items, once I move on to the query of the dataverse table, the value changes, and there is no other action in between that would change them.  This causes every record to error.  I have spent now nearly 60 hours trying to figure this out and cannot find a solution anywhere.

 

Here is how my flow is built.....

ScottRMeredith_0-1655990783552.png

 

ScottRMeredith_1-1655990813673.png

 

ScottRMeredith_2-1655990842853.png

 

ScottRMeredith_3-1655990884916.png

 

ScottRMeredith_4-1655990911891.png

 

 

And here are the outputs I am getting.....

 

Here is when the variable is initially set in the apply to each loop...

ScottRMeredith_5-1655991016571.png

 It passed through my switch without any manipulation....

ScottRMeredith_6-1655991100208.png

Here is where it queries the Dataverse table....the employee number it is using is not the one in the variable it is set to use.

ScottRMeredith_7-1655991161679.png

 

I have no hair left, so please help.

 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
ScottShearer
Super User
Super User

@ScottRMeredith 

If you have concurrency control turned on for your loop, turn it off as that is likely the cause of your issues.  Setting the value of a variable inside of a loop with concurrency turned on will cause unpredictable values for the variable.

 

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Scott

View solution in original post

5 REPLIES 5
ScottShearer
Super User
Super User

@ScottRMeredith 

If you have concurrency control turned on for your loop, turn it off as that is likely the cause of your issues.  Setting the value of a variable inside of a loop with concurrency turned on will cause unpredictable values for the variable.

 

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Scott

I do have that turned on to speed things up, but will turn it off and see how that goes.  I will let you know.  Thanks.

@ScottRMeredith 

Assuming that I am correct about the issue, you can eliminate the need for the variable by using an expression instead of the variable in your List Rows action.

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Scott

I am using the variable because I am in my switch action getting the length of the employee number (4, 5, or 6 characters) and then adding back in leading zeros.  In Dataverse the employee number is stored as a SLT, while in SP it is a number field.  So I was using the variable to be able to change it based on the length and still reference the same named piece of data.  I am open to learning a different way to accomplish the same thing, but don't know how currently.

 

Also for the limited time it has been running, each record is not erroring out right off the bat like it was previously so it looks promising.

 

Thanks

 

VictorIvanidze
Community Champion
Community Champion

Use this:

concat(substring('000000', 0, sub(6,length(variables('varEmpNum')))), variables('varEmpNum'))
--------------------------------------------------------------------------------------
Contact me if you are interested in custom Power Automate development.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Super User 2 - 2022 Congratulations 768x460.png

Welcome Super Users

The Super User program for 2022- Season 2 has kicked off!

Users online (2,581)