How to add a conditional step?

How to add a conditional step?

Conditional steps are one of the basic elements of most created macros. What are they and how are they used in automation?

What is a conditional step?

Conditional steps in the AUTOMADE tool are based on a logical condition that relies on values drawn from specific variables. Let’s briefly explain what these terms mean:

 

A condition or “conditional instruction” is one of the most important concepts in programming. It is designed to invoke a specific run/algorithm depending on the value of a variable. A variable is a value that has a specific name. We write more about variables and how they are used in the AUTOMADE tool in the article X.

 

Example 1:

The company has a cost invoice acceptance policy, in which any invoice over £10,000 must be accepted by the manager. AUTOMADE robot can check all invoices and send an e-mail to the manager asking for approval for each invoice above this amount. All other invoices are automatically booked.

 

Example 2:

The variable could be an Excel cell with an age designation. We want to generate and send enrolment forms for free hearing tests to older employees in the company. A condition could be to specify that the action will be performed if the number in the cell is over 60. According to the condition set, the message will be automatically sent only to these people.

 

Example 3:

We work in sales and came up with the idea of sending birthday wishes to customers. Keeping track of the birthdays of dozens or hundreds of customers is something that can easily be forgotten in the hustle and bustle of work. This is therefore an ideal task for the AUTOMADE application.

 

By setting a conditional step based on the date of birth, we can create a macro that will browse the customer database every day and in case of a birthday, it will automatically create a personalized birthday card.

How to add a conditional step in the AUTOMADE tool?

Adding a conditional step can be done while editing a macro in the advanced view or while recording. Before we can do this, however, we need to determine the variables that the condition will use. A variable can be, for example, a column in an Excel sheet, today’s date, the day of the week and many others.

How to create a variable?

A cell in an Excel sheet is a common example of a variable. If we have a document with personal data and one of the columns contains age, we can set an age variable that we will use further, for example, to send messages to people over 60.

 

To do this, we go to the selected step “Read Excel cell” and in the step settings on the right we enter the variable name.

Importantly, the variable name we set must meet several conditions:

 

  • it cannot have spaces,
  • it cannot contain special characters and Polish characters
  • additionally, it is recommended to describe variables with the camelCase notation (e.g. firstName) or by separating them with the underscore character (e.g. first_name)

 

In the following case the macro is used to fill PDF documents. The value from the Name column in Excel will be read from the cell and stored in the firstname variable. Variables are fixed to each column – first name, last name, date of birth, PESEL and gender.

Once the name is entered, we can use that variable to create loops and conditional steps. You can read more about loops here, and let’s move on to creating conditional steps.

Adding a conditional step in macro editing mode

You can use several options to add a conditional step to an existing macro in the advanced view:

 

  1. Manual addition of a conditional step

To manually create a conditional step, add a new step by selecting the + button from the top menu, then look for the “Conditional Step” button in the left-hand panel and move it to the macro action list:

As you can see, a conditional step block has appeared, with further blocks – Execute and Otherwise.

 

  • In the Execute field, place the steps that are to be executed if the set condition is met
  • In the Otherwise field, enter the steps to be taken if the condition is not met

 

Such steps can be for example sending a message, filling in a document or a worksheet depending on the age of the person in the worksheet. When creating a macro, add these steps from a list of already recorded steps or create new steps using the Add Step function.

 

Once you have added them, define a condition for the step, for which the panel on the right is used:

What do the following functions mean?

 

The expression specifies the actual condition. Here, determine which variables will be taken into account and select Operator.. In the first Value field, we select the variable on which the further effect will depend. All the predefined variables will be available in the drop-down menu. They must be entered in the format “dollar sign-clause”, i.e. ${variable name}

 

In the Operator field, select what the variable should take into account. This is the rule on which the effect of the condition will depend. It can depend on the contained content or e.g. a numeric value, i.e. “equals”, “is greater than” etc.

 

For example: if your intention is to generate and send forms to senior employees of a company:

  1. the first variable must be determined from the age cell
  2. the operator is “equal to or greater than
  3. the second value is e.g. “60”.

 

 

An additional possibility is to add another condition using the button marked with a plus (+). This would be necessary if we wanted to generate documents for employees aged between 18 and 25. Such a condition would look as follows:

 

Between the conditions there are additionally options “and” and “or”, which we use depending on whether we want both conditions to be fulfilled or one of them is enough.

As you can see, there is another + button under both conditions. Multiple such conditions can be added. For a full description of expanding conditional steps, see the article “Combining conditions in a conditional step”.

Adding a conditional step while recording

The second option is to add a condition while in recording mode. This requires typing the conditional statement manually, so knowledge of a programming language (Javascript/Beanshell) is required. To add a condition in recording mode, select “Add condition” from the tools

After pressing it, a window will appear, in which we can manually enter a conditional step expression in the script language. As we said, in order to be able to do that, you need to have the desired variables defined first. Remember to keep the correct format ${variable name} when entering variables.

Adding note is optional.

 

Once the condition is approved, the next steps will be recorded within the conditional block. To stop recording within a conditional block, press the “End Condition” button at the bottom of the menu.