Description
This activity allows you to apply various business logic to algorithms and perform certain actions depending on the conditions you set.
The conditions can be set either using JavaScript syntax or using a visual editor. We will describe it in more detail in the following section of this article.
Parameters
There are two modes of working with the "Condition" parameter in the "If...then" activity:
- Basic
- Advanced
Basic - this mode involves using the visual editor to set simple conditions.
When you click on the "Edit condition" button you will see such a window:
At the top of the window there is a working area consisting of three parts - data component - operator - data component.
At the bottom of the window are available elements - data and operators.
Data can be a boolean type - true
or false
, explicit data - text or number, and a variable. Operators define a condition for comparing components.
Suppose that the condition should be: "If the variable price
is greater than 1000
, then". Let's set this condition using the visual constructor. To do this:
- Drag and drop the "Variable" block into the left-hand data component. After dragging it, you will be able to set the name of the variable. In our case it will be
price
. If you want to change the variable name, click on the pencil icon. - Next, drag and drop the "Number" block into the right-hand data component. You can set or change the value of the component similar to the first action. Set the number to
1000
. - Now drag the "Greater" block to complete the condition.
This way, the condition will look like this:
Click Save. The "If...then" block will appear ready to work on the canvas.
In the toolbar on the right you will also see the specified condition.
Advanced - allows you to manually write code in JavaScript syntax to create a condition within the "If...then" activity.
Similar to the example above, we set the same condition - whether the value of the price
variable is greater than 1000
using JavaScript code.
JavaScript input field
This is what a complete algorithm with a condition might look like. Here we have some variable with a value assigned to it. We apply the "If...then" check to it (if the price is greater than 1000) and output the result to the console.
The algorithm from the example above and the result - the checked condition
Here are more examples of setting conditions using JavaScript:
price > 10 //checks if a number is greater than 10
(milk_price < 10) && (bread_price > 15) //checks if both conditions are met
ocr_data.includes('Total') // checks if data returned by an ocr engine has the word "Total"
number_in_system === user_input // checks if some number in system is of the same data type as the user input and if they are equal in values
number_in_system == user_input // checks if the values are the same if one of the variable is automatically converted to the type of the other variable