Hi,
Here is a little code example below of a 3 sum calculation with 3 foreach relating on the same data.
Is there any way to optimize this code to keep a single foreach left and then storing the sum outputs in a an array or a list of 3 items (or other)?A kind of:
local!sumArray: a!foreach(
sum(), sum(), sum()
)
local!sumA: sum( a!forEach( items: ri!data, expression: if (fv!item.weight > 0, 1, 0 ) ) ), local!sumB: sum( a!forEach( items: ri!data, expression: if (fv!item.weight > fv!item.weight2, 1, 0 ) ) ), local!sumC: sum( a!forEach( items: ri!data, expression: fv!item.weight, ) )
Discussion posts and replies are publicly visible
That is a great improvement. I will update my local version. Thanks :-)
Thanks Stefan, it works great! To use the rule in a validation of a text field I only added refreshvariables in the IsIbanValidHelper, to avoid an error. Thanks a lot.
Thank you Stefan Helzle, this will help me a lot!!!!
The implemented algorithm is
https://en.wikipedia.org/wiki/International_Bank_Account_Number#Modulo_operation_on_IBAN
The trick here is, to use the initial parameter of the reduce function like a shared memory dictionary which is modified on each iteration.
Have fun :-)
IsIbanValidHelper: dict(any) if( isnull(ri!dict.bban), ri!dict, a!localVariables( local!checksum: mod(tostring(ri!dict.checksum) & left(ri!dict.bban, ri!dict.num), 97), local!bban: right(ri!dict.bban, len(ri!dict.bban) - tointeger(ri!dict.num)), { checksum: local!checksum, num:7, bban: local!bban } ) ) IsIbanValid: iban(text) a!localVariables( local!iban: upper(stripwith(ri!iban, " ")), local!checksum: left(local!iban, 4), local!ban: right(local!iban, len(local!iban) - 4), local!bban: local!ban & local!checksum, local!replaceChars: {touniformstring(enumerate(10)), "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}, local!replaceNums: {enumerate(10), enumerate(26)+10}, local!newbban: joinarray( a!forEach( items: enumerate(len(local!bban)), expression: displayvalue( local!bban[fv!index], local!replaceChars, local!replaceNums, "" ) ) ), local!result: reduce( rule!IsIbanValidHelper( dict:_, dummy:_ ), { checksum: 0, num: 9, bban: local!newbban }, enumerate(ceiling(len(local!newbban) / 7)) ), tointeger(local!result.checksum) = 1 )
Hi Stefan, me too I need this solution for a IBAN validation!!!... Thanks
Sure. Please connect me here in Appian community and let's have a direct chat.
Hi Stefan,
do you still have the code for checksum algorithm for IBAN Validation in Appian?
You would be of great help to me.
Thanks!
Thanks Stefan, I keep this function on hand :-)
Thank you Mike, sugasanr.It's great ! I did not know we could do that with a dictionnary.
There is an option using reduce() which allows you to pass data from one iteration to the next. I used it to implement a block based checksum algorithm for IBAN validation. But in this case I would prefer this simple one.