Skip to main content
March 1, 2023
Question

Update value of a local variable to new values inside a foreach loop

  • March 1, 2023
  • 16 replies
  • 0 views

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.

    16 replies

    harshitb6843
    March 1, 2023

    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. 

    March 1, 2023

    I want to 

    remaininamount=principalamount-interest,

    principalamount=remainingamount

    for each iteration. Could u pls let me know how to do this?

    harshitb6843
    March 1, 2023

    What is your end goal? Tell me your expected output. 

    stefanhelzle0001
    Brainy
    March 1, 2023

    Check my blog post about how to implement more complex algorithms in Appian.

    appian.rocks/.../

    March 1, 2023

    Hi Stefan, saw the post. Could u help me with applying recursion in this scenario that i mentioned above?