Skip to main content

Perform bulk modifications or loops with repeating steps

For some action sequences, performing a certain step for each entry on a list can help you save time and make your automated action more efficient. For example, when an asset turns out to be broken, you want to cancel all upcoming reservations and inform the requester.

By using repeating steps in an action sequence, you can let TOPdesk perform one or more steps a set amount of times. Helpful for applying changes on multiple cards or triggering loops after triggering an action on just one card. For example, a repeating step can help you cancel all reservations or update all persons linked to an asset.

remark

Repeating steps is a more advanced functionality in Action Management and Asset actions, but at the same time a powerful functionality when setting up automations in TOPdesk. Before diving into the world of repeating steps, we advise you to first make yourself familiar with setting up more basic action sequences.

Repeating steps can be used in combination with regular action sequence steps. To keep this chapter focused on what makes repeating steps different from those other steps, we don’t discuss every detail of its setup.

In this chapter, we will first have a look at the features that are available when using repeating steps. After that, we will discuss an example in which this functionality is used.

warning

A risk with creating loops is that it can lead to too many repetitions. As protection against configuration errors, the number of times an Automated Action can be triggered on the same card within 15 minutes is limited to 100.

Adding a repeating step to an action sequence

Similar to an HTTP step, a repeating step can be added to an action sequence. You will find the option for adding a repeating step after you have decided to trigger an action sequence as action.

remark

Repeating steps are currently available for Asset actions, webhooks, and scheduled actions.

In this topic, we mainly look at the various functionalities within a repeating step. In Example for setting up repeating steps, we have a look at an example and use the FreeMarker language to get more out of this functionality.

To add a repeating step to an action, click on Add a repeating step to add a step that should be performed multiple times within your action sequence.

'Add a repeating step' on a new action.

After clicking the ‘Add a repeating step’ button, a new step is added to the action sequence.

Tip

You can move an existing step into a repeating step by clicking the move_into_repeating_step.png icon in your existing step (the arrow pointing in the direction of the targeted repeating step).

Name the repeating step to distinguish it from other repeating steps in the overview.

Features in repeating steps

Besides various options you might recognise of other steps in action sequences, a repeating step contains the following fields and sections to help you set up your step:

  • Number of repetitions: this field helps you determine how often the step should be repeated, and specify the list that the action is repeated on. A common way to fill this field is by starting your action sequence with a regular HTTP step. In that step, request a list, and use the length of this list as the number of repetitions. In the repeating step, you then use this list to tell TOPdesk which (mostly) cards to use. For an example and more information, see Example for setting up repeating steps.

  • Steps to be repeated: contains options to add an HTTP step, email step, and/or Generate Document step to your repeated step. Each of the steps added here will be repeated the number of times determined in ‘Number of repetitions’. These are the actual steps that TOPdesk will perform multiple times.

  • Continue repeating: determine whether the step must continue repeating no matter if the previous repetition was successful (Always), or whether the repeating step must stop when the last repetition failed (Only if all previous repetitions succeeded).

  • Execute this step: limit the execution of the step. Apply custom conditions, only execute if all previous steps succeeded, combine the two or always execute the step.

Repetition index i

By filling in the field ‘Number of repetitions’, you tell TOPdesk how often the whole repeating step must be repeated. To know how far down the list of repetitions TOPdesk is when executing the action sequence, it uses the variable i. This is the ‘repetition index’. The repetition index is incremented by one every time the step is repeated, up until the set number of total repetitions is reached.

Within the repeating step, use [i] in the code of your step to get to the ith element of the list. This helps you in getting information about that element on the list and use it in your step.

By using [i] in your code, you tell TOPdesk to not simply repeat all steps in exactly the same way, but to perform the steps for element i in your list. See Example for setting up repeating steps below for this concept being used.

Example for setting up repeating steps

In this example, we have a look at using repeating steps to update the mobile phone number on a Person card every time the phone number on the Mobile phone asset card assigned to them has been changed.

We’ll focus on the extra steps you need to take to set up your repeating step. Therefore, we will not discuss the trigger (a change on the Mobile phone asset card), and various basic parts of the action sequence such as Authorization headers and variables. These are explained in more detail in Integrate and automate with Action Sequences.

tip

Go to knowledge item KI 15531 on My TOPdesk to find another repeating steps example, including the JSON file to import the action sequence in your environment.

Create the basis for your list

In this example, the list consists of all Person cards that are linked to our Mobile phone asset. We get this list by performing a GET request to our TOPdesk. The first step in our action sequence is a regular HTTP step. Create this first step by clicking Add an HTTP step. We call it ‘Get all assignments’. Then, use the following URL, based on the Update an existing asset API endpoint:

/tas/api/assetmgmt/assets/${_card["id"]!}/assignments

tip

Create a connection of the type 'This TOPdesk'. Select this connection in your HTTP step and your TOPdesk URL, as well as the credentials for the authorization, are automatically recognised.

The variable ${_card["id"]!} represents UNID (system field) and is added via the Insert Value button. This ensures that the list of assignments of the relevant asset is requested. When this step is performed, the list of all assignments (including all persons the mobile phone is assigned to) is returned in the response body.

Figure 1. The first step in our action sequence
The first step in our action sequence


Create the repeating step

Next up, we add a step that fills the mobile phone number on every Person card we just requested. Click Add a repeating step to add a new step to the action sequence that gives us the possibility to perform one or more steps for every element on the list.

In Number of repetitions, enter the following:

${_responses["Get all assignments"]["body"].persons?size}

To break down this input:

  • ${_responses["Get all assignments"]...} tells TOPdesk to look at the response of the ‘Get all assignments‘ step.

  • ["body"] tells TOPdesk to go to the body of the response. This is the usable content of the response we get in the first step.

  • With .persons, TOPdesk navigates to the ‘persons‘ element in the response body of the first step.

  • ?size in FreeMarker language gives you the length of the list. In other words, it counts how many Person cards are listed in the response.

tip

Find more information about how to find the right values in a response body, see Example for specifying which JSON or XML value to use.

Now that we know how often the step must be repeated, we tell TOPdesk which actions to actually repeat. To update a field on Person cards, we use the Update a person by id PUT API endpoint to fill the URL:

/tas/api/persons/id/${_responses["Get all assignments"]["body"].persons[i].person.id}

Let’s break down this input again:

  • /tas/api/persons/id/ is the first part of the API endpoint, with which we tell TOPdesk what we want to achieve: update a person card based on its id.

  • ${_responses["Get all assignments"]...} helps TOPdesk to find the right id of each Person card. We tell TOPdesk to look at the first step in our action sequence.

  • With ["body"].persons[i].person.id, we tell TOPdesk to look for the list of persons in the response body, and find the person number i in the list. Of this person, take its ID, as this is the value that is expected by the API endpoint. Notice how i is used to find the id of the next person on the list for every repetition.

Because TOPdesk increments i by 1 with every repetition, TOPdesk knows that with every repetition it has to grab the information for the next person on the list.

We now tell TOPdesk what to actually do on the Person cards. For this example, in the Body field, we enter the following to use the Asset card’s phone number field and fill the Person card’s Mobile Number field:

{"mobileNumber": "${_card["phone-number"]!}"}

Please mind that ‘phone-number’ is a custom field in Asset Management. You can use whatever field you want to copy information from.

This will result in the following repeating step:

Figure 2. The repeating step in our action sequence
The repeating step in our action sequence


At last, we use the Continue repeating field to set whether the loop should always attempt to complete the list, or to stop when a repetition has failed.