If - Condition
Declaration
<AMIF EXPRESSION="text" USECOMPLEXUI="YES" />
Description
Begins a block of steps that are executed conditionally. The If condition along with an Else step are conditional statements that can perform different operations during the course of a task depending on the result of an expression evaluation. If the result evaluates to TRUE, the task will execute the block of steps immediately following this step up until an End if step is encountered. If the result evaluates to FALSE, the block will be skipped and execution will proceed directly after the End if step (or if an Else step is encountered, the task will execute that block of steps instead, up until an End if step is encountered).
Practical usage
Used to perform different activities for different decisions.
Parameters
General
Property | Type | Required | Default | Markup | Description |
---|---|---|---|---|---|
Expression | Text | Yes | (Empty) |
| Indicates
a valid BASIC expression. The Simple
method allows you to enter a simple expression by entering two
values and selecting from the drop-down list of equality operators
to be used to compare those values. The Complex
method allows entry of more elaborate expressions. NOTE: All literal strings (strings to be taken as themselves) must be
enclosed in double quotes (Example: "string literal"). |
Examples
- Copy and paste the sample AML code below directly into the Task Builder Steps Panel.
- To successfully run the sample code, update parameters containing user credentials, files, file paths, or other information specific to the task to match your environment.
Example 1
This is a simple task using If condition activity - results to TRUE.
<AMIF EXPRESSION="1 = 1"><AMMESSAGEBOX>The result of the expression is TRUE.</AMMESSAGEBOX><AMELSE /><AMMESSAGEBOX>The result of the expression is FALSE.</AMMESSAGEBOX></AMIF>
<AMSHOWDIALOG MESSAGE="The result of the expression is TRUE." />
<AMELSE />
<AMSHOWDIALOG MESSAGE="The result of the expression is FALSE." />
<AMIF ACTIVITY="end" />
Example 2
This is a more complex task that demonstrates the following:
- Use of the Input Box activity to ask the user a question and retrieve the answer.
- Use of custom BASIC functions.
- Use of the IF activity.
- Use of Expressions.
<AMSHOWDIALOG WINDOWTITLE="Sample Task" BUTTONS="ok_cancel" ONSECONDBUTTONCLICK="stop">This sample task demonstrates the following:
1) Use of the Input Action to ask the user a question and retrieve the answer
2) Use of Custom BASIC Functions
3) Use of the IF action
4) Use of ExpressionsRemember you can always stop a task in progress by pressing CTRL-ALT-END. Press okay to continue running the task or Cancel to stop now.
</AMSHOWDIALOG>
<AMVARIABLE NAME="theanswer" DESCRIPTION="" VALUE="" />
<AMSCRIPT SCRIPT="Function SquareNumber(thenum)SquareNumber = thenum * thenumEnd Function"></AMSCRIPT>
<AMSHOWDIALOG ACTIVITY="input" MESSAGE="What number would you like to square?" RESULTVARIABLE="theanswer" />
<AMIF EXPRESSION="IsNumeric(theanswer) = true" USECOMPLEXUI="YES" />
<AMSHOWDIALOG>The number %theanswer% squared is:%SquareNumber(theanswer)%</AMSHOWDIALOG>
<AMELSE />
<AMSHOWDIALOG>The text "%theanswer%" is not a valid number. Please re-run and enter a valid number.</AMSHOWDIALOG>
<AMIF ACTIVITY="end" />