Skip to main content
Verify the version tags to ensure you are consuming the intended content or, complete the latest version.

Automation looping

In Pega Robot Studio, you have different options available to control the flow of data and iterate through a collection of items. The options for iteration include both the use of the Switch statement and looping components. The Switch statement allows you to identify specific actions based on either a single input for a collection or list. 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.

Switch

The Switch component allows you to set conditional logic of events for a list or collection of inputs. Much like the Switch construct in Object-Oriented programming, the component lists different courses of action, including a Default option if the other options are not chosen. Unlike the loop component, the Switch component allows you to run through a collection or list and specify multiple execution paths while integrating loop components within those different paths.

Screenshot showing the position of the switch component in a toolbox menu.

In the following image, an automation has a specific input into the switch statement. Instead of displaying a message for only one specific action, each action has a corresponding message. The automation also checks the action to see if the input contains the word Robots; if found true, a message is displayed that tells users that the system is turning on the robots.

Screenshot showing the use of Switch component to display customized message depending on the chosen option.

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.

Screenshot showing the position of the ForLoop component in a toolbox menu.

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.

Screenshot showing a use of the For Loop in automation to loop through the list of beverages in store and check its availability.

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.

Screenshot showing the position of the ListLoop component in a toolbox menu.

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.

Screenshot showing automation using the ListLoop to proceed through the list of administration items and select proper action.

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.

Screenshot showing a process of creating a query.

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.

Screenshot showing the automation that uses a query.

Check your knowledge with the following interaction. 


This Topic is available in the following Module:

If you are having problems with your training, please review the Pega Academy Support FAQs.

Did you find this content helpful?

Want to help us improve this content?

We'd prefer it if you saw us at our best.

Pega Academy has detected you are using a browser which may prevent you from experiencing the site as intended. To improve your experience, please update your browser.

Close Deprecation Notice