Percent Signs in AutoMate

A percent sign is used as a special character in AutoMate to indicate the beginning and end of an expression. This allows variables, constants and other expressions to be entered in any parameter of a task's properties that accepts expressions. For example: %1+1% inside a task will resolve to 2 at runtime. 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 5%, specify 5%%. At runtime the double percentage 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 action with the properties shown below.

The code that executes this example is entered below.

NOTE: The code below can be copied and pasted directly into the Steps pane of the Task Builder.

 

 

<AMVARIABLE NAME="Var1">Batman</AMVARIABLE>

<AMVARIABLE NAME="Var2">Robin</AMVARIABLE>

<AMSHOWDIALOG>The currrent value of Var1 is %Var1%</AMSHOWDIALOG>

<AMSHOWDIALOG>The currrent value of Var2 is %Var2%</AMSHOWDIALOG>

<AMSET VARIABLENAME="Var1">%Var2%</AMSET>

<AMSHOWDIALOG>The new value of Var2 is %Var2%</AMSHOWDIALOG>

 

See Also

Local Variables

Constants

Arrays

Expressions

Expression Builder

Datasets

See Also


Local Variables | Constants | Arrays | Expressions | Expression Builder | Datasets


↑ Top of Page