Appian Community and Appian Academy are being upgraded. As a part of the upgrade, Appian Community is currently in read-only mode, and user registration is disabled until August 3. We apologize for any inconvenience this may cause, but a more secure, stable, and performant Community experience is coming soon!
The new Appian Community launches August 3, followed by Appian Academy on August 7. During the migration, Appian Community Edition, Appian Academy, Documentation, Certifications, Instructor-led Customer Training, Partner Sales Training & Accreditation, and Forum (for Appian Partners and Customers only) will remain available.
How to implement while or do while logic in expression rule?
Discussion posts and replies are publicly visible
We do not have a looping function that would stop based on a condition. All you can do is use a!forEach just like Harshit mentioned in his answer. You might have to do it in multiple steps, at least two. The first one to exclude values greater than 31, for which you can use filter, reject, wherecontains, and/or a!forEach. Second step would be to update each item in array based on the condition specified inside the while loop, for this you can use a!forEach.
shreeharshan0678
a!localVariables( local!keyValPair: { { id: 1, value: "This is a text value" }, { id: 2, value: 12 }, { id: 3, value: {1,2,3,4} } }, displayvalue( 12 /*Desired value that you want*/, local!keyValPair.value /*Place where you want to search it for*/, local!keyValPair.id /*Field of the matching index that you wnat to return */, "Not available" /*Default value if the desired value was not found*/ ) )
As others have said you cannot break out of a loop in Appian, you have to let it run to the end of the provided list. Typically what I do is output 'null' when my condition is not met, and the value I do want when the condition is met, and then remove the nulls from the generated list.
Thank you for your help.
Thank you, I will look into that.
Here's trivial example to illustrate the idea:
fn!reject( a!isNullOrEmpty, a!localVariables( local!myList: fn!enumerate(10) + 1, a!forEach( items: local!myList, expression: if(fv!item = 5, fv!item, null) ) ) )