Summary
This tutorial demonstrates how to use the If Condition activity in Automation scripts.
In this tutorial you will learn:
You will need:
Watch a video presentation of this tutorial: Automation - Using the If Condition Activity.
When building an Automation script you might find that you want to execute a set of activities only when a certain condition exists. In this case you want to use the If Condition activity. The If Condition allows you to instruct your script to execute one or more activities if a condition you specify is true.
You can add several branches to the If Condition activity to simultaneously evaluate more than one condition. This allows you to have multiple code paths in your script. Please note that the If Condition is not an If Else statement. Each branch only executes if the condition resolves to true. Multiple branches can be true. If all branches resolve to false, then none of the branches execute.
To learn how to use the If Condition to automate exception reporting, see the tutorial, Automate Exception Reporting. In that tutorial, you learn how to use the If Condition activity to evaluate the row-count variable generated by a Select to File activity. The evaluation is then used to determine whether or not to distribute the report.
The most obvious use case for the If Condition activity is to evaluate the value of a variable. So in this tutorial you will evaluate the value of the return code variable generated by the Run Program activity.
Click in the Program field. Browse to and select your sample batch file or executable. If you don't have a batch file, for the purpose of this demonstration you could select the Notepad executable at
C:\Windows\notepad.exe
Notice that Toad provides a default name for the return code variable. You can modify the return code variable name by entering a new name or by changing the activity's name.
The return code variable from the Run Program activity is listed. Double-click it to add it to the expression editor.
Note: Variables from any other previous activity plus any stored bind variables are also listed.
Complete the expression to read: #Run_1_RCODE# = 0. Notice that in the Variables list, each variable name is surrounded by hash (#) symbols. If you manually enter the variable name, you must surround the name with hash symbols.
Click
After the script executes, review the Log to see the steps the script performed. If the Run Program executes successfully, then the run code variable is set to 0, the expression in the left branch evaluates to TRUE, and the message generated is "Success."
If the Run Program execution was not successful, then the expression in the right branch evaluates to TRUE, and the message generated is "Failure."
In our example, the If Condition activity has two branches. However, the If Condition can have more than two branches or just one branch.
See Schedule Your Script to learn how to schedule the Automation script.
© 2024 Quest Software Inc. ALL RIGHTS RESERVED. 使用条款 隐私 Cookie Preference Center