cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Cdgf
Frequent Visitor

How to prevent For loop of adding values in list from previous items

I am trying to sum all values of a specific field in a list of opportunity lines which is working as it should. However, I am now trying to sum the values for each user linked to their opportunity lines, but it is adding all values from previous items.

 

This means that it is adding the numbers for the first user as it should, but for the next user it is adding both for the previous and current one, and on and on. 

 

How can I prevent the for loop of doing this? I have tried several things but cannot make it work.

 

I am storing the total of two different values in temporary variables, and then for each user the value is set, which will be stored in a whole new entity in Dynamics. As you can see, the values should be 40.000, 24.300 and 135.000, but instead it is adding themCapture1.PNGCapture4.PNGCapture2.PNG

1 ACCEPTED SOLUTION

Accepted Solutions
pagonza
Microsoft
Microsoft

Hello @Cdgf 

 

I think you have the problem due to the variable isn't reseting.

 

May this can help you:

 

- reset the variable after update your record, set the value of the record to 0 at the final of the apply to each

- If this not work, try to don't use variables, may is possible do all the operations on the update the record?

 

Hope I can help you!

View solution in original post

2 REPLIES 2
pagonza
Microsoft
Microsoft

Hello @Cdgf 

 

I think you have the problem due to the variable isn't reseting.

 

May this can help you:

 

- reset the variable after update your record, set the value of the record to 0 at the final of the apply to each

- If this not work, try to don't use variables, may is possible do all the operations on the update the record?

 

Hope I can help you!

View solution in original post

Cdgf
Frequent Visitor

For some reason I had not thought about that at all and tried multiple other options, but it works perfectly! Just reset the variables after the new entity was created in the for loop

 

Thank you!

Helpful resources

Announcements
Process Advisor

Introducing Process Advisor

Check out the new Process Advisor community forum board!

MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Top Solution Authors
Users online (28,092)