For a list of integers, I need to check the desired value by calling a service. I would like to stop calling the service, only I get the desired output. Any suggestions, please.
Discussion posts and replies are publicly visible
This needs to be calculated in an expression rule on load.
In Appian there is only a foreach(). And this cannot be interrupted.
But using the reduce() function, while still iterating on all list items, you can decide whether to call your service based on previous results.
https://appian.rocks/2022/08/29/complex-algorithms-in-appian/
There is no break concept in Appian.
But using reduce, call the service for list of integers. For every iteration append the desired output to a list and check if the list contains your desired output. If the list contains the output just return null instead of calling the service.
This could potentially be one of the few times that it's helpful to call an expression rule recursively.
Pattern: rule!RULE_myFunction(list of integers)
if( (list index 1 meets condition), [Return Value], rule!RULE_myFunction(ldrop(list of integers, 1)) /* pass in the same array, but with the first element removed */)
Thanks Mike Schmitt for your suggestion. It worked.
Stefan Helzle Soma thanks for your time.
thanks for confirming!