Repeat Number of Times

Estimated reading: 4 minutes 44 views

This activity executes a set of activities repeatedly for a specified number of times. It helps workflows perform repetitive operations without duplicating logic, supporting scenarios such as retries, batch processing, or executing a task a fixed number of times.

How does this activity differ from Retry Scope and For Each?

Retry Scope: Retries an activity only if it throws an exception during execution.

For Each: Iterates only through the number of items available in a collection or list.

Repeat Number of Times: Executes a set of actions for a defined number of times or can be used to iterate with the next value for each repetition.

Why do you need this activity?

This activity is useful when you already know how many times some action(e.g., selecting a date, choosing the value from dropdown etc.) needs to be repeated. It doesn’t depend on conditions or lists just repeat the same action at fixed number of times.

Simple examples:

1. Press a Refresh button 5 times.
2. Move through a calendar (Datepicker) step by step to reach the right date.

Properties

Input

Repeat number of times: Specifies to provide the number of times the activities need to be repeated.

Start at: Specifies to enter the value from the which the “CurrentItem” parameter should start from.

For Each: Helps to iterate and repeat the set of activities in loop with the “CurrentItem” value. You can customize the name.

MISC

Display Name: Displays the name of the activity. The activity name can be customized, which aids in troubleshooting.

SkipOnError: Specify the “Boolean” value as “True” or “False.”

True: Continue executing the workflow regardless of any errors thrown.
False: Halt the workflow if it encounters any errors.
None: If the option is left blank, the activity will, by default, behave as if “False” were chosen.

Version: It indicates the version of the feature being used.

Example of Using This Activity

To select a date from the Datepicker control, let’s look at an example using a sample website.

Required Variables:

1. One String variable (InputDate) – to store the date to be selected from the Datepicker control.
2. One Int32 variable (DaysDiff) – to provide the number of times the action should be performed.

Prerequisite: Install Web Automation and Keyboard Automation packages.

Steps to Create the Bot:

1. Open the website, add a Click activity from Web Automation, and detect the Datepicker box to open the calendar.
2. Add an Assign activity with the following expression:

a. DaysDiff = (DateTime.Now.Date – DateTime.Parse(InputDate).Date).Days

3. Add another Assign activity:
a. DaysDiff = Math.Abs(DaysDiff)

4. Add a Write Log activity to check the calculated number.
5. Add an If activity with the condition: Now < DateTime.Parse(InputDate)
6. Then branch:
a. Add a Repeat Number of Times activity.
b. Set the Repeat Number of Times property to DaysDiff.

7. In the Do sequence:
a. Add a Shortcut Key activity (Keyboard Automation) and select the standard key Right.
b. Add another Shortcut Key activity and select Enter.

8. Else branch: Follow the same steps as above, but in the Shortcut Key activity, select Left instead of Right.

Explanation:
This bot checks the input date provided in the variable and calculates the difference between the current date and the input date. Based on this difference, it repeats the navigation action (Right/Left) the required number of times. If the input date is greater than the current date, it moves forward (Right). Otherwise, it moves backward (Left). Finally, it selects the date.

Example 2: Using the “For Each” Function

A simple example to print values repeatedly using the Message Box activity.

Steps to Create the Bot:

1. Add a Repeat Number of Times activity.
2. Set the Repeat Number of Times property to 12.
3. In the Start At property, enter the value 1.
4. This indicates that the current item will start from 1 as the initial number.
5. In the Do sequence:
a. Add a Message Box activity (Notification) and provide the input string as CurrentItem.
CurrentItem is the variable available in the For Each property, and it can be customized if needed.
b. Provide a title for the message box.
6. Execute the bot.

You will see that the count increases with each iteration of the loop.

Share this Doc

Repeat Number of Times

Or copy link

CONTENTS