a!localVariables( local!principalAmount:ri!loanAmount, local!totalMonths: ri!tenure * 12, local!interestForOneMonth: round(ri!interest / 12, 2), local!interest: ( local!interestForOneMonth * local!remainingAmount, ) / 100, local!remainingAmount:local!principalAmount-local!interest, a!forEach( items: enumerate(local!totalMonths) + 1, expression: { local!interest, local!principalAmount, local!remainingAmount,
a!save(local!remainingAmount,local!principalAmount-local!interest,), a!save(local!principalAmount, local!remainingAmount), } ), )
For each iteration of the for loop i want to update the value of local!principalAmount and local!remainingAmount as shown above. Kindly let me know how we do this in Appian.
Discussion posts and replies are publicly visible
You cannot change the values of a variable in a rule once assigned. Also, a!save() only works on human interactions/events and hence it won't work. You can just create a new dictionary, or array and just assign it to a new variable and consume it. Or directly consume it without assigning it.
I want to
remaininamount=principalamount-interest,
principalamount=remainingamount
for each iteration. Could u pls let me know how to do this?
You could use something like this.
a!localVariables( local!principalAmount: ri!loanAmount, local!remainingMonths: ri!tenure - 1, local!emi: ( (local!principalAmount / 100) * ri!interest ) / 12, { { month: 1, emi: local!emi }, if( local!remainingMonths = 0, {}, rule!LoanCalculator( loanAmount: local!principalAmount - local!emi, tenure: local!remainingMonths, interest: ri!interest ) ) } )
Hi Harshit, this would not help bcoz the principal remains the same for all the months here. My principal for the second month is principal for first month - interest. Principal for third month is principal for second month-interest. Interest is also calculated based on the renewed principal amount.
That is what we are doing on line 13. Isn't it?
loanAmount: local!principalAmount - local!emi will remain same always right? since local!principalamount and local!emi are same always....
Nope. They'll change with every iteration. This is a recursion. Create an expression rule with the name as 'LoanCalculator' and paste the above definition. Then save it. Should work!
Awesummmmmm! It worked. Thanks Harshit!!!
Hi! I want to use the same practice as Anuradha C , but in a different context. The logic I am trying to achieve is "if my local variable equals 0, execute this code and make the variable equal to 1 so the next iteration of the forEach loop meets false in the if condition and executes the else code". Is there a way to achieve this with local variables? And if not, how can I make this logic happen?
appian.rocks/.../
I can't quite grasp how I am going to implement the Iterative Algorithm in my code. Am I going to use it to update a local variable? Or as an if condition? I don't quite understand its use.
Using reduce, you can pass data from one iteration to the next. While not the same as modifying a variable, you can use it to implement iterative algorithms.