Hi,
I have a requirement to update the actual array value and the updated values in the array I need to use it in my further iterations in a for loop, for eg., below is the sample code for my requirement
a!localVariables( local!arrayToLoop: { {credit: 10, debit: 100, txn1: 0, txn2: 150, txn3: 0}, {credit: 100, debit: 0, txn1: 0, txn2: 150, txn3: 0}, {credit: 0, debit: 100, txn1: 0, txn2: 150, txn3: 0}, {credit: 0, debit: 100, txn1: 0, txn2: 150, txn3: 0}, {credit: 0, debit: 0, txn1: 0, txn2: 150, txn3: 0}, {credit: 75, debit: 80, txn1: 0, txn2: 150, txn3: 0}, {credit: 65, debit: 0, txn1: 0, txn2: 150, txn3: 0}, {credit: 0, debit: 100, txn1: 0, txn2: 150, txn3: 0}, {credit: 50, debit: 70, txn1: 0, txn2: 150, txn3: 0}, {credit: 40, debit: 100, txn1: 0, txn2: 150, txn3: 0} }, a!foreach( items: local!arrayToLoop, expression: if( fv!isFirst, fv!item, if( tointeger( fv!item.credit ) > 0, fv!item, updatecdt( fv!item, { credit: index( local!arrayToLoop.credit, fv!index - 1, 0 ) } ) ) ) ))
Output of the above code is
[credit:10,debit:100,txn1:0,txn2:150,txn3:0]; [credit:100,debit:0,txn1:0,txn2:150,txn3:0]; [credit:100,debit:100,txn1:0,txn2:150,txn3:0]; [credit:0,debit:100,txn1:0,txn2:150,txn3:0]; [credit:0,debit:0,txn1:0,txn2:150,txn3:0]; [credit:75,debit:80,txn1:0,txn2:150,txn3:0]; [credit:65,debit:0,txn1:0,txn2:150,txn3:0]; [credit:65,debit:100,txn1:0,txn2:150,txn3:0]; [credit:50,debit:70,txn1:0,txn2:150,txn3:0]; [credit:40,debit:100,txn1:0,txn2:150,txn3:0]
Here in my current code the actual array is not getting updated, only the fv!item is getting updated so when I check the the "credit" value of the previous ideration it is still "0" as per the original array
But the expected outout is
[credit:10,debit:100,txn1:0,txn2:150,txn3:0]; [credit:100,debit:0,txn1:0,txn2:150,txn3:0]; [credit:100,debit:100,txn1:0,txn2:150,txn3:0]; [credit:100,debit:100,txn1:0,txn2:150,txn3:0]; [credit:100,debit:0,txn1:0,txn2:150,txn3:0]; [credit:75,debit:80,txn1:0,txn2:150,txn3:0]; [credit:65,debit:0,txn1:0,txn2:150,txn3:0]; [credit:65,debit:100,txn1:0,txn2:150,txn3:0]; [credit:50,debit:70,txn1:0,txn2:150,txn3:0]; [credit:40,debit:100,txn1:0,txn2:150,txn3:0]
Discussion posts and replies are publicly visible