Percent Signs

Overview

Percent (%) signs are used as a special character in Automate Desktop to indicate the beginning and end of an expression. Automate Desktop interprets the text between the "%" to be an expression, and therefore, should not be taken literally. This allows variables, datasets, constants and other expressions to be entered in any parameter of a task that accepts expressions. For example, entering the following syntax inside a task will resolve to 2 at runtime:

%1+1%

Below are some common scenarios which involve the use percent signs.

Sending literal percent sign

To send a literal percent sign, simply escape the percent character. Doubling the percent sign is known as "escaping" the percent sign. For example, to send the literal text 100%, specify 100%%.

At runtime the double percent signs will be recognized and converted into one.

All percent signs are recognized and evaluated by Automate Desktop that are contained in any parameter that accepts expressions. For example, if an Web Browser - Open activity contained the URL:

http://www.fortra.com/urc%admin%/kb_add.cfm

During runtime, Automate Desktop will detect the percent signs contained in the URL (%admin%)and automatically classify admin as an expression, which eventually fails the task with the error A variable in the expression does not exist or is misspelled. In such cases, simply doubling the percent signs will resolve the issue:

http://www.fortra.com/urc%%admin%%/kb_add.cfm

Concatenating two values in an expression

In some cases, it is necessary to concatenate two variables, functions, or some combination thereof. In this case it is critical to remember that two percent signs always mean a literal percent. So the following will NOT work:

%variable1%%variable2%

(INCORRECT)

At runtime, Automate Desktop would actually see the expression as variable1%variable2 which would result in a Syntax Error. The proper way to combine two values in an expression is to use the ampersand (&) character as follows:

%variable1 & variable2%

 (CORRECT)

Common misconception

A common misconception is that percentage signs are required anytime a variable is used. This is not always the case because percentages surround expressions which may or may not contain variables. For example, in situations where Automate Desktop requires a variable name (for example, in the 'Set Variable' action), only the variable name is required. It is permissible, however, to use an expression to specify the variable name so the resolved variable is used.

For example, assume we created a variable named Var1 with an initial value of "Batman" and a variable named var2  with the initial value of "Robin". If we wanted to change the value of Var1 from "Batman" to "Robin", we'd use a Set Variable activity with the parameters.

Example

NOTE:
  • 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.

The AML code that executes this example is as follows:

Copy
<AMVARIABLE NAME="Var1" VALUE="Batman"></AMVARIABLE>
<AMVARIABLE NAME="Var2" VALUE="Robin"></AMVARIABLE>
<AMSHOWDIALOG>The current value of Var1 is %Var1%</AMSHOWDIALOG>
<AMSHOWDIALOG>The current value of Var2 is %Var2%</AMSHOWDIALOG>
<AMVARIABLE ACTIVITY="set" VARIABLENAME="Var1">%Var2%</AMVARIABLE>
<AMSHOWDIALOG>The new value of Var1 is %Var2%</AMSHOWDIALOG>