I am having an array like {22,10,12,11, 8, 17}. I need an expression which return the index where individual array value or sum of previous values is greater than or equal to 20.
For example: The output should be {1, 3, 5, 6}.
22 (22-20) => 2 (index = 1)
2 (remainder from previous value) + 10 + 12 (24-20) => 4 (index = 3)
4 (remainder from previous value) + 11 + 8 (23-20) => 3 (index = 5)
3 (remainder from previous value) + 17(20-20) => 0 (index = 6)
As there is no while/do-while loops in Appian so it seems bit difficult to get the desired output with foreach loop.
Discussion posts and replies are publicly visible
This is not straight-forward but doable. What are you trying to achieve? Maybe there is a better way to do that.
Well, these values in array are number of rows / lines of a table or grid. So assuming 20 is the max size of rows a page can have, I need to add the page breaks if any of the grid is not having enough rows left of the page.
Not the most optimized solution, just gave it a try:
-Expression Rule Name: DA1_trialCommunity
-Rule Inputs:
arr: List of Number(Integer)prev: Number(Integer)ans: List of Number(Integer)index: Number(Integer)
if( a!isNullOrEmpty(ri!arr), ri!ans, a!localVariables( local!sum: ri!prev + ri!arr[1], local!rem: if( local!sum >= 20, local!sum-20, local!sum ), rule!DA1_trialCommunity( arr: ldrop(ri!arr,1), prev: local!rem, index: ri!index+1, ans: if( local!rem <> local!sum, append(ri!ans, ri!index), ri!ans ) ) ) )
You can further optimize it and also use reduce function.
Thanks Aryan . Its doing what's needed.