If - Condition

Declaration

<AMIF EXPRESSION="text" USECOMPLEXUI="YES" />

Related Topics   

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).

NOTE: All If activities must be followed at some point with an End If step to mark the end of the code block that is to be executed if the expression is TRUE. For ease of use, by default, any If activity added to the Task Builder's Steps panel is always followed by an End If activity.

Practical Usage

Used to perform different activities for different decisions.

Parameters

General

 
PropertyTypeRequiredDefaultMarkupDescription
ExpressionTextYes(Empty)
  • EXPRESSION="%1 &lt; 2%"
  • "EXPRESSION="%1 &gt; 2%"
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").

Description

Error Causes

On Error

Examples

NOTE:
  • The sample AML code below can be copied and pasted directly into the Steps Panel of the Task Builder.
  • Parameters containing user credentials, files, file paths, and/or other information specific to the task must be customized before the sample code can run successfully.

Example 1

This is a simple task using If condition activity - results to TRUE.

Copy
<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:

  1. Use of the Input Box activity to ask the user a question and retrieve the answer.
  2. Use of custom BASIC functions.
  3. Use of the IF activity.
  4. Use of Expressions.
Copy
<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" />