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?
What is your end goal? Tell me your expected output.
Check my blog post about how to implement more complex algorithms in Appian.
appian.rocks/.../
I have a principal loan amount, rate of interest and number of months.
for each month, i want to calculate the interest. once the interest is calculated, the renewed principal will be old principal - interest.
for the next month the interest will be calculated on the renewed principal...and so on...
Hi Stefan, saw the post. Could u help me with applying recursion in this scenario that i mentioned above?
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....