I want to iterate a a!save() expression for 10 (n times) when I press a button
Discussion posts and replies are publicly visible
a!localVariables( local!X, { a!buttonArrayLayout( buttons: { a!buttonWidget( label: "Button", style: "OUTLINE", saveInto: a!forEach( items: enumerate(10)+1, expression: a!save( local!X[fv!index],fv!item ) ) ) }, align: "START", marginBelow: "NONE" ) })
What do you want to save using a!save() ? Can you provide us with more details
A foreach would do that. But what do you want to achieve?
Hello vijayp6380 You will have to use a!forEach() and run your a!save()(Not recommended). Also do you have any particular variable that defines the number of iterations that has to be performed? What will this a!save() perform exactly? If the Rule Input or Local variable that you are going to use for the target is same, You don't need to do the loop. May be a better explanation of your requirement would help all of us to give a better solution.
vijayp6380 You shouldn't be doing that unless you are sure that there is no better way to do what you are trying to achieve.
For example, the above code doesn't need a forEach loop if you just want to update the items of an array. It can be simplified as
a!save( local!X, enumerate(10)+1 )
But if you have a particular requirement which cannot be solved without a loop, then you have the code from Venky.
I want to sort a number array in Appian without using sort function
I want to sort a numbers array in Appian without using sort function
This has been discussed on community quite a lot of times now - community.appian.com/.../function
if( a!isNullOrEmpty(ri!inputArray), {}, a!localVariables( local!data: a!forEach( items: ri!inputArray, expression: { value: fv!item } ), todatasubset( local!data, a!pagingInfo( startIndex: 1, batchSize: - 1, sort: a!sortInfo( field: "value", ascending: or(ri!ascending) ) ) ).data.value ) )
Harshit Has given the answer above for your requirement.
There is a need of a function which sorts elements of an array. I think such function does not exist today.