I am new to Appian and I need to write a rule that takes an array of CDT objects; updates all of their "id" and "loanId" values to null; and returns them.
I have been trying to use a foreach loop as follows but the data won't change. what am I doing wrong?
a!localVariables( local!assestsLiabilitiesDetails: ri!assestsLiabilitiesDetails, expression: a!forEach( items: local!assestsLiabilitiesDetails, expression: { fv!item: a!update(fv!item, "id", null('type!{http://www.appian.com/ae/types/2009}Integer')), fv!item: a!update(fv!item, "loanId", null('type!{http://www.appian.com/ae/types/2009}Integer')), } ), a!save(target: ri!assestsLiabilitiesDetails, local!assestsLiabilitiesDetails) )
Thank you in advance for the help!
Discussion posts and replies are publicly visible
Hi, I hope the below example helps.
a!localVariables( local!inputs: { { id: 1, loanid: 6789, acctNum: "ACC1567" }, { id: 2, loanId: 7823, acctNum: "ACC83049" } }, local!idUpdatedToNull: a!forEach( items: local!inputs, expression: a!update(fv!item, "id", null()) ), local!loanIdUpdatedToNull: a!forEach( items: local!idUpdatedToNull, expression: a!update(fv!item, "loanId", null()) ), local!loanIdUpdatedToNull )
Here is a slightly more optimized version:
a!localVariables( local!list: { a!map(id: 1, loanid: 6789, acctNum: "ACC1567"), a!map(id: 2, loanId: 7823, acctNum: "ACC83049") }, a!forEach( items: local!list, expression: a!update(fv!item, { "id", "loanId" }, { null, null }) ) )
Thank you, Mathieu, for sharing the optimized code. Previously, I was trying to update two indices/fields with a single value, which resulted in an error. Your code has helped to understand the error.
that solved my issue, thank you for the assist