• Documentation
  • Workato Blog
  • Product Blog
  • Return to Workato
  • Login
  • Automation Institute
  • Documentation
  • Community Forums
New Topic
Discussions Enhancement Requests Core Product Features
B

Beth

started a topic about 7 years ago

Sort step and Escape Loop step

When in a For Each loop, it would be helpful to be able to sort the records, and to have an Escape Loop step, which would act like a Stop, but rather than stopping the whole recipe, would take you to the next step after the Loop chunk. This would allow for the equivalent of much more intelligent searching among a list.

Example use case, find the most recent open invoice for a customer in QBO:

Search invoices based on Customer ID. 

Sort records in chronological order... 

Loop...

Check the first one. Is its Balance>0? No?

Check next. >0? No? 

Check next... >0? Yes! 

Do things with this invoice. 

Don't bother checking any more in the list; I'm done. Escape to next top-level step.


8 people like this idea

Phuong Nguyen

said about 7 years ago

Hi Beth. Thanks for making this suggestion. I will definitely file an issue for this request and raise it up with my team. I will update you here as soon as I hear anything from them. Cheers!


1 person likes this
A

ArtsPool Services Inc.

said almost 7 years ago

I agree. A loop becomes much more powerful logic if you can escape it. We could really use this feature.

D

Daniel Carvallo

said about 6 years ago

Sorting would be great for Repeat Actions!


1 person likes this
J

Jeremy Farber

said almost 4 years ago

badly needed

Alvin Ee

said over 3 years ago

Unfortunately, we do not have a native function that would escape a loop. However, we do have a suggested workaround. What you will need to do is have the loop nested in an error monitoring step, and have a stop with error within the loop when a certain condition is met. Upon receiving an error, the "on error" portion of the recipe will be started. An example of such a flow can be found in the link here: https://www.workato.com/recipes/962695?st=e9ecc4#recipe




As for a sorting function, you can use a ruby action to sort an array, or the collections feature in Workato. 

  1. Ruby


Use formula mode and the .to_json formula on the list pill to convert it to a JSON array. After obtaining the JSON array, use the Ruby action and sort the unsorted object by entering the following code:


  • Ascending


unsorted.sort_by { |hash| hash['key_to_order_by'] }


  • Descending


unsorted.sort_by { |hash| hash['key_to_order_by'] }.reverse

 

An example recipe can be found HERE.

 

       2. Collections [Business Plus & Above]

 

After obtaining the JSON object, use the Collections by Workato action to 


  • Create a list in Collection [Using the JSON object as the input]
  • Query list in Collection [To sort the JSON object]


An example recipe can be found HERE.

Login to post a comment

Still can't find your solution?

Send us a ticket, we will try our best to assist you with your problem

Documentation
Developer's Library
Tutorials
eBooks
Product Hour
Product Blog
Workato Blog
Product updates
Customer Stories
© Workato 2022   Privacy   Terms   +1 (844) 469-6752
  • Documentation
  • Workato Blog
  • Product Blog
  • Solutions
  • Forums
  • Tickets
  • Log in
  • Return to Workato
Topic views count