Conditional Statements. If-Else
Commands for handling decisions. If-Else block
At this stage, several problems immediately arise:
- How to determine that there are exactly two files?
- How to determine that these are suitable files?
- What to do with them next, and how to transfer them to the server for analysis?
Let's start with the simplest. Select File provides files as an array (even if it's one separate file), and the number of elements in the array can be found using the Array Size block. It takes an array as input and returns an Integer with the number of elements in the array as output.
Comparison blocks
Next, you need to make a comparison. Find out if the actual quantity corresponds to our expectations. The Equal block is suitable for this. It takes two values as input and gives its answer, whether they are equal or not. The first value will be passed from the previous block (number of files), and the second value will be specified by ourselves (2).
Pay attention to what other comparison blocks are available for use. Often it is necessary to check not the fact of equality but whether the value falls into a certain range (Less, Greater Or Equal, and other blocks are suitable for this) or, in general, the very fact of the presence of any value (Is Null).
The result of checking the Equal block comes in the form of a Boolean. True if the values match, or False otherwise. This information can be used to decide on further actions; this is where the If-Else block comes in handy.
If-Else
Previously, we only used blocks that were executed in a strict order, one after the other. The If-Else block allows you to create a fork and, depending on the boolean value on the input, directs the flow in one of two possible directions.
In our example, there is an option when the number of files selected by the user is not equal to two. In this case, it will be possible to show the appropriate notification and stop the business process. To do this, use the Show Notification block, connect it with the False option and set the necessary parameters (Type = Error, Text = Please select 2 (TWO) files).
If there are really two files, then the process will continue along the True path and move on to the next stage - checking that the files you need are selected and their format matches expectations. To do this, you need to find out the name of each file and check its extension.