Variable Syntax for Emails and Scripts

You can use variables in workflows to access Commander metadata and allow the workflows to integrate with other systems.

For workflows, you can insert variables in workflow emails; you can also pass variables to workflow scripts.

Using the script editor

In any text field that supports variables, you can click to open the script editor and select variables for the current context.

Depending on the context, the editor allows you to input a single line or multiple lines.

Multi-line script editor

With the multi-line script editor, syntax highlighting is available:

  • Execute embedded script workflow steps
  • Execute script workflow steps
  • Dynamic list scripts

You can also use keyboard shortcuts to expedite common actions, such as finding and replacing. For a list of keyboard shortcuts for the multi-line script editor, see Default Keyboard Shortcuts in the Ace documentation.

Basic variable syntax

The basic syntax for using variables in scripts and emails is:

#{variable.subvariable}

For example:

#{request.cpuCount}

Variable values that may contain spaces

If a variable value contains spaces, enclose the entire variable in double quotes. For example, if a VM's name may contain spaces, use:

"#{target.deployedName}"

Custom attribute syntax

When using custom attributes, always enclose the attribute name in single quotes (whether or not the attribute name contains spaces). The attribute name is case sensitive. For example:

#{target.customAttribute['Primary Application']}

Named argument in scripts

When passing a variable to a script that uses named arguments, always enclose both the named argument and the string in double quotes, like this:

"/Computer:This name has spaces".

The following example won't work:

script.vbs /vmname:"#{target.deployedName}"

You must use the following syntax instead:

script.vbs "/vmname:#{target.deployedName}"

Execute script workflow steps

Commander allows you to add both Execute Script and Execute Approval Script steps to workflows. Execute Approval Script steps have a special behavior. If the script output returns exit code 0, the workflow proceeds to the next step; if the script returns exit code 1, the workflow fails, and the request is automatically rejected.

For more information about workflow steps, see Workflow Steps Reference.

For more information about variables that can be used in workflow steps, see Add Data to Workflows With Variables.

Paths in command line for script steps

When configuring the command line for Execute Script and Execute Approval Script steps, you must use an absolute path to the executable, even if the executable exists in the Windows path to ensure that the script is executed in the right location.

Formatting the email body

The <a> tag is automatically added to links in emails (only the http protocol is supported). For example, if the value of a custom attribute is a link, the value will be formatted as a link in the email.

If you don't use HTML markup in the email body, the body is assumed to be plain text; <br> and <p> tags are automatically added for new lines.

If you add HTML markup to the email body, no additional tags are added.

Date format

Dates returned by variables are of the form yyyy/mm/dd hh:mm:ss.

Permissions

The scripts or executables that are called will run under the Commander service account. Make sure that this account has the appropriate permissions or the script may fail to run.