Automation looping
In Pega Robot Studio, you have different options to control the data flow and iterate through a collection of items. The options for iteration include the use of several looping components. Looping iterates through a section to validate, perform, or complete actions against a collection or list of items. Any interrogated application that accesses a data table or list can use one of the loop options. The following loops are the types that are available for automation use:
- ForLoop
- ListLoop
You access the loop options under the Loops header in the Work Flow section of the Toolbox.
ForLoop
The ForLoop component enables repetitive logic execution using the same elements as the ForLoop structure in other programming languages. This structure allows you to complete an action either a specific number of times until the conditional expression is true or until a break event node is triggered. Because of the ForLoop's nature, it only works on collections in applications that are accessible through indexing. This index is required for the loop because it has to specify the number of times a repetitive action occurs.
The design block contains the main methods and events for the ForLoop component and allows for either dynamically setting or hard-coding the loop's parameters. You also set the properties of this component on the Properties grid.
If you have an automation that you want to continue running until there is no more work or until a specific value is reached, ForLoops loops work for these situations. You can also use the ForLoop component to iterate through items for automations that need to investigate data tables. Data tables in interrogated applications may not expose the methods that contain a list's index or item count. Therefore, you should use ForLoops with tables that expose this property.
In the following image, the automation retrieves a list of beverages from an inventory site. The loop checks the list against a beverage request, and if the item is found, a message displays stating the beverage is in inventory.
ListLoop
The ListLoop component allows you to read items from a list or a collection and execute events for each item. Unlike the ForLoop component, the ListLoop component loops through the count of items and reads the list's contents and outputs for further processing in the automation.
Unlike the ForLoop, the ListLoop component does not require the index to run through all loop items. ListLoops iterate through a collection without any regard for the list order. Therefore, you use it with an interrogated table that does not expose methods that include the index. When you cannot access the table's index, set the UseKeys property to True. This allows you to access the GetClones method of a collection, retrieve the items within it, and return the value regardless of the order of objects.
In the following example, the automation takes a list of personalized administrative actions sent to a user. It then reads each item, and if the item contains a message regarding robots, displays a specific message.
Queries
The Query option is also available as an additional way for you to perform a looping action through a collection without using a looping component. In the Properties Design block for the list, selecting the Query option for the automation instead of selecting the Index property allows you to search through the list for a specific item. Similar to the ForLoops component, this action is available only on design blocks that require a key or where indexing is an option for locating the necessary item depending on the business request's scope.
In the following image, the automation receives a beverage request for Ipoh Coffee from a website table. If the queries find a match, the automation shows a positive message, and a message stating that the drink is unavailable is displayed if the query is unsuccessful.
Check your knowledge with the following interaction.
This Topic is available in the following Module:
Want to help us improve this content?