If - Contains text

Declaration

<AMIF ACTIVITY="contains_text" TEXT="text" SUBSTRING="text" ACTION="text (options)" USERE="YES/NO" USECASE="YES/NO" FOUNDTEXTVARIABLE="text" INDEXVARIABLE="text" />

Related Topics   

Description

Determines if the text to look for is contained within the target text and returns TRUE or FALSE depending on the outcome. Optionally, this activity can determine whether the target text starts with or ends with the text to look for. 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

Commonly used to check the contents of a piece of text and perform conditional actions depending on whether it is found.

Parameters

General

 
PropertyTypeRequiredDefaultMarkupDescription
If textText (Options)YesContains
  • ACTION="contain"
  • ACTION="not_contain"
  • ACTION="start_with"
  • ACTION="end_with"

Specifies the condition should check for the characters to be contained or not contained within the text. The available options are:

  • Contains - The If block will be executed if the text to look for is contained in the target text.
  • Does not contain - The If block will be executed if the text to look for is not contained in the target text.
  • Start with - The If block will be executed if the target text starts with the text to look for.
  • End with - The If block will be executed if the target text ends with the text to look for.
Target textTextYes(Empty)TEXT="TheTargetText"The text to search from. As with every text parameter, if the data you wish to write is contained in a variable, simply enter the variable name surrounded by percentage signs to resolve it to it's contents at runtime (for example, %VarName%).
Text to look forTextYes(Empty)SUBSTRING="TextToFind"The text to search for inside the target text. As with every text parameter, if the data you wish to write is contained in a variable, simply enter the variable name surrounded by percentage signs to resolve it to it's contents at runtime (for example, %VarName%).
Cases SensitiveYes/NoNoNoUSECASE="YES"Specifies whether the search performed should be case sensitive. If selected, case sensitivity is turned on. If disabled (default) case sensitivity is turned off.
Regular expressionYes/NoNoNoUSERE="YES"

If selected, the Text to look for parameter contains a regular expression. If disabled (default), the Text to look for parameter contains literal text.

Advanced

 
PropertyTypeRequiredDefaultMarkupDescription
Index of matched text into variableTextNo(Empty)INDEXVAR="var2"The name of an existing variable to receive the index position of the text that was found.
Place matched text into variableTextNo(Empty)FOUNDTEXTVARIABLE="var1"

The name of an existing variable to receive the text that was found. This parameter is useful if a regular expression was entered in the Text to look for parameter.

Description

Error Causes

On Error

Example

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.

Description

A simple task that determines if the target text contains the word "ran." If so, a message box will be displayed.

Copy
<AMVARIABLE NAME="theTargetText" VALUE="The rabbit ran away."></AMVARIABLE>
<AMIF TEXT="%theTargetText%" SUBSTRING="ran"><AMSHOWDIALOG MESSAGE="The variable named theTargetText contained the word &quot;ran&quot; " /></AMIF>
<AMSHOWDIALOG MESSAGE="The variable named theTargetText contained the word &quot;ran&quot;" />
<AMIF ACTIVITY="end" />