Examples

Here detailed examples of each of the loop activities will be shown

For Each Activity

To show the basic working of the For Each activity, we can create a sample bot that goes through each of the mails in an email account of your choice and save the attachments of each of the mail messages, if it has any. The following are the steps to create the specified bot:-

  • Create a new workflow and Drag and drop the get IMAP mail activity to the workspace. Connect the start activity to the Get IMAP mail activity.

  • Specify the required field inputs like account credentials, mail folder, Server Configurations etc..

  • Drag and drop the For Each activity and connect the two activities. Specify the output variable of the Get IMAP mail activity in the Collection property field of the For Each activity and also give a loop name.

  • Connect the For Each activity with a Save Attachment activity. Provide the Output folder path where the attachments are to be saved and specify the Mail Message property field of the Save attachments activity with the output(Item) variable of the For Each activity which contains each of the mail in the current iteration of the collection.

  • Add the End loop activity at the end and connect the Save attachment activity to it and specify the same Loop name that we have given in the For Each activity.

The final workflow would be like in the following screenshot :

Click on the Run button in the studio to start the execution of the bot. We can view the downloaded attachments from the mails (if any) in the specified output path in the Save attachments activity.

Repeated Loop Activity

To show the basic working of the Repeated loop activity, we can create a sample bot to search and get the top 10 news of a user-specified city and save the retrieved data in a text file with Datetime with the given city as its filename. The following are the steps to create the specified bot :

  • Create a new workflow and Drag and Drop the Show Input Message box activity to input the desired city whose top 10 news that are to be retrieved.

  • Create a web-recorded session using Web Recorder in the Ui Automation tab item in the studio.

  • Drag and drop Create Counter activity to create an index (NewsIndex) to iterate through each element in the website.

  • Drag and drop 2 Format Text activities and a Get DateTime activity, and use one Format text activity to store the text content to be given in the output file (ex: "Top 10 News in ${CityName} City are as follows:") and use the other Format text and Get date time activities to create a file path with current date time and specified city.

  • Create a text file using the Write File activity with the new filename.

  • Drag and Drop Repeated Loop activity to iterate all the activities (between Repeated loop and End loop activities) a specific number of times (ex: 10 times) to retrieve the essential news from the website.

  • Create a web-recorded session to extract each headline from the website.

  • Use the Append Line activity to append each headline obtained from the preceding web-recorded session to the text file created using Write text file activity.

  • Drag and drop Increment activity to increment the NewsIndex created earlier using create counter activity and connect the Increment activity to an end loop activity to complete the workflow.

The final screenshot of the workflow is as follows :

Click on the studio Run button to start the execution of the bot. An input prompt will appear next to input the city as soon as the bot is executed.

We can view the retrieved new headlines from the given file path where the output file is saved.

Last updated