Loops in BMC Remedy ARS

Modern, and no so modern, programming languages have the concept of loop, that is, a sequence of code that is executed repeatedly a controlled number of times. This concept, jointly with the conditional sentences, conforms the basic flow control tool set. For, while, do … loop, are common loop commands. But this commands are not present on Remedy. So, There are no loops in Remedy? False. They are, but not as you would expect.

In this post I will review the most common looping techniques available in Remedy.

Where to use these techniques

The technique explained below can be use with active links or filters without any difference between them. I will use “workflow element” to denote a filter or active link and “guide” to denote a filter guide or active link guide.

The for loop: a fixed number of iterations

The first kind of loop is the one that at the beginning of the loop you exactly know the number of iterations you want to repeat your code. You have a counter that increases or decreases until arriving to some value, that marks the end of the loop.

First, create a number field (can be display only) to store the counter. All the workflow to be repeated must be placed at a guide. The guide will hold the next workflow elements:

  • A first workflow element that sets the counter to the initial value.
  • A label indicating the start of the loop
  • The core of your loop, that is, the workflow that you want to repeat
  • A last workflow element with a qualification that controls if the counter has reached the maximum (or minimum) value. The IF action (maximum reached) must be void, that is, take no action. The ELSE actions must be, increase the counter and goto the label indicating the start of the loop.

You can also create a for loop without using a guide and using a goto to an execution number. I do not recommend this way of doing since it is easy to forget that these execution numbers hold a loop and place foreign elements, that will be repeated with the loop.

The while loop: repeat while satisfying a condition

This kind of loop is very similar to the previous one, but you don’t use a counter. You repeat your code until some condition is not true. This kind of loop is very common in character processing, where you process one character after other and ends when there are no character left.

As in the for loop, you must create a guide and place inside the next workflow elements:

  • A label indicating the start of the loop
  • The core of your loop, that is, the workflow that you want to repeat
  • A last workflow element with a qualification that checks if the condition is satisfied. The IF action (Satisfied) must be goto the label indicating the start of the loop. The ELSE action must be void.

In fact a for loop is a particular case of a while loop.

The for each loop: processing a set of requests

This is by far the most common kind of loop in Remedy. You can do a query to a form and want to process a set of workflow elements for each request returned by the query.

The easiest way of doing it is to create a table field that points to the form you want to query with a qualification that restricts the returned elements to the ones you want to obtain. The query can be dynamic, I mean, based on other fields.

Then you create a guide based on the column fields of the table. When you call this guide you can specify to repeat the guide for each request present in a table field. selecting the table field and following all the request of the table you have created a for each loop over the table field.

Posted on by Jose Huerta in Developing solutions, Newbies

Add a Comment