Guidelines for handling the control flow of your script
The script's control flow is the order in which commands run. A group of commands is called a block, and a control flow statement results in one or more blocks running. In IBM RPA, bot scripts are a group of command calls that run one after the other.
Your script should have up to two exit points
An exit point is where the control exits a script, terminating the running bot. Your script should have only up to two exit points: the end of the script and the end of the unknown exception handling subroutine. For more information about how you can handle unknown exceptions in your script, see Handling unknown exceptions.
Your script should end when there is no other command available to run.
Consider raising exceptions
When you need to stop the bot's runtime because of a control flow statement, consider using the Throw exception (failTest
) command to raise an exception. For example, you
need to program your script to check if a file required in the process exists, and you need to stop the script if the file doesn't exist. Instead of just stopping the script, raise an exception.
When you stop your bot by raising an exception, you program your bot to explicitly warn about a faulty process. You can program the bot to log as much data about the accident to help the debugging process.
Avoid using "Go to" constructs
Commands like Access (goto
) or Access if (gotoIf
) can add confusion and complexity to your script. Even in small scripts, avoid using them, Instead, user other commands the Control flow command category.
Evaluate efficiency gains versus losing legibility
Try writing simple blocks of commands. Avoid writing complex or complicated blocks.
A simple script is easier to maintain. A complex script is harder to maintain because the maintainers might need to know advanced concepts, or the script integrates with multiple components. A complicated script is hard to maintain because the maintainers don't understand what the script does, or, in other words, the script is not legible.
Sometimes you might want to increase the efficiency of your bot, which might lead to complex or even complicated solutions. Only favor efficiency at the cost of legibility when efficiency is a key determinant in the project's approval with well-defined limits.