To process steps depending on some condition, add a step of type "Choose". Such steps consist of two parts: a "when" part and an "otherwise" part.
Abstract representation of a job which includes conditional processing
As shown in the image above, both the "When" part and the "Otherwise" part require an execution step. Also, the "when" part requires an expression. This expression dictates which of the two parts will be executed when the job runs. Namely, if the "When" expression evaluates to Boolean true, then Step C will be executed. Otherwise, step D will be executed. Therefore, the processing sequence of the abstract job illustrated above will be as follows (provided that there are no execution errors):
1.Step A
2.Step B
3.Step C or D, depending on the expression
4.Step E
5.Step F
For example, in the step illustrated below, FlowForce will execute the built-in delete function only if the expression "fileexists" evaluates to Boolean true.
Note that "fileexists" must have been declared in a previous step (or perhaps as an input parameter), for example:
Otherwise, FlowForce would display a syntax validation error:
If you intend to pass the result of a "Choose" step to another step, or declare it to be of a particular type, ensure that each "When" and "Otherwise" condition produce the same return type. Otherwise, the return type of the "Choose" step is the common return type of all "When" and "Otherwise" branches, which might trigger validation errors. |
For example, consider a job that checks the value of a numeric parameter temperature to tell you whether the weather is hot or normal. Such a job might look as follows:
In the job above, notice that Declare return type as is set to "string". If temperature is greater than a particular value (in this example, 35), a string expression is computed, namely "It is hot". Otherwise, the string expression "It is normal" is computed. So far, both the "When" and the "Otherwise" condition produce a string, so the job can be successfully saved and executed.
However, if we had left the "Otherwise" condition empty, the job would have triggered a validation error, as shown below.
The reason is that the expected return type of the job is "string" (as indicated by the Declare return type as setting). If the "Otherwise" branch is not defined, it computes to nothing. "Nothing" is not the same as a string; therefore, this triggers the validation error.
The jobs illustrated on this page use FlowForce expressions. For an introduction to FlowForce expressions, see FlowForce Expressions.