Percent Signs in Automate

Overview

Percent (%) signs are used as a special character in Automate to indicate the beginning and end of an expression. Automate 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 that are contained in any parameter that accepts expressions. For example, if an Open Web browser activity contained the URL:

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

During runtime, Automate 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 as shown below:

http://www.networkautomation.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 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 requires a variable name (i.e. 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 shown below.

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.

The AML code that executes this example is displayed below.

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>