How to calculate a creating object in a changing object?
Hello everyone, I'm struggling by trying to calculate the total costs of all the calculated rules. Everytime when a customer adds a new ‘let's say calculated rule’ the total costs will be reset to ‘0’ value because then it's focused on the new calculated rule.. and totally forgets the rule that has been created before. I can't figure it out, all help will be appreciated. The changing object of ‘All total costs’ should be $CalculatedRule/Cost* $CalculatedRule/Number* ( all numbers... )
Fouad El Yakobi
You are now calculating the total of a single line (BerekenRegel).
I would suggest to store that information as an attribute ('Totaal’) in BerekenRegel
After calculating every line you can then simply maken a list of all BerekenRegels and sum the “Totaal’ values. This is the value you want in Totaalberekening/Totalekosten.
You will have to update this after each change in a BerekenRegel and after adding or removing one.
I got it. Thank you!
Fouad El Yakobi
It looks like instead of calculating the total price of the list, you're calculating the total price of a single line of costs. For the total, you can do two things:
Take the old value of $Totaalberekening/Totalekosten and add/subtract the new value. This is a little risky since if you make one mistake somewhere the total is always messed up, so I would recommend against this
Retrieve a list of all orderlines, and do an aggregate list action (sum) of the total of each line. This should get you a more accurate total when the user changes, adds or removes things from the order and is more robust than method 1.