Thank you for your feedback.
Form temporarily unavailable. Please try again or contact docfeedback@servicenow.com to submit your comments.
Versions
  • London
  • Kingston
  • Jakarta
  • Istanbul
  • Helsinki
  • Geneva
  • Store
Close

Expressions in Cloud Management

Expressions in Cloud Management

You can use expressions in policy actions to set or override values. You can use expressions in blueprints to access attributes of resources and to map values to request form fields.

Expression mapping to blueprints

You can access blueprint attributes with expressions. The expression in the Mapping column defines Blueprint attributes for each operation. For example, the Location attribute, which appears on the request form for a virtual machine, is accessed in the following expression: {$parameter.Location}.

Expression types

Definitional expressions
Definitional expressions are a form of early binding and are evaluated when the user submits the stack request form (when stack or resource provisioning starts). Definitional expressions do not have access to the data that is generated during Orchestration. Definitional expressions are enclosed in curly braces. For example: ${parameter.CloudAccount}
Runtime expressions
Runtime expressions are a form of late binding and have access to the data that is created during Orchestration (for example, stack items). Runtime expressions are evaluated when called during an Orchestration run. Runtime expressions are typically used for dot-walking to data in tables. Runtime expressions are enclosed in parentheses. For example: $(Stack.items[VM1].attributes[node_id])
Definitional/Runtime expressions
Some expressions include both definitional and runtime expressions.
Complex expressions
You can nest expressions of any type within other expressions.

Sample expression

Here's a sample expression from the Scripts background along with an explanation of each parameter.

$(ci.cmdb_ci_nic[$(Script:CMPVMNICs.getNICs[arg=$(Stack.items[Virtual Server].attributes[sys_id])])].private_ip)
  • $(ci: Runtime expression to retrieve data from table.
  • cmdb_ci_nic: CI for NIC (Network Interface Card).
  • $(Script: Script based expression.
  • CMPVMNICs: Script include.
  • getNICs: Function inside a script include.
  • arg: Arguments to script include function. Arguments are separated by "," when there are multiple attributes.
  • $(Stack.items: Runtime stack expression to retrieve stack item from a stack. Argument is the alias specified in blueprint.
  • Virtual Server: Alias of resource used in blueprint.
  • $(Stack.items[Virtual Server].attributes[sys_id]): Retrieve sys id of stack item ("Virtual Server") resource instance in a stack
  • private_ip: attribute from cmdb_ci_nic. Replace with public IP if required.
Table 1. Expressions
Expression and syntax Type Description Example
Simple parameter mapping expression

${parameter.}

Definitional Use to retrieve values from input attributes of processes like blueprint provisions. Data is not fetched from tables. Maps values from one layer to another (Blueprint > Resource > CAPI).

This format of expression is used in the policy.

  • ${parameter.BillingCode} returns the billing code.
  • ${parameter.formData.CatalogAttributeType} takes a catalog attribute that is submitted on the request form in the User Portal.
  • ${parameter.userData.userId} takes the ID of a user working on the request form in the User Portal.
Stack item expression

${Stack.items[]}

$(Stack.items[])

Definitional/Runtime A CI instance in the CMDB represents each stack item. Use Stack Item expressions to look up first-level properties on the CI that back the stack item or on the stack item itself.

This format of expression is used in the policy.

  • ${Stack.items[VirtualServer1].attributes[sys_id]} is a definitional type expression that gets the sys_id of a virtual server in a stack. VirtualServer1 is the alias of a resource block that is used in the stack.
  • $(Stack.items[VirtualServer2].attributes[sys_id]) is a runtime type expression that takes the sys_id of a virtual server that is a part of a stack.
  • ${Stack.items[vm1].attributes[node_id]}reads the node_id attribute of the CI that was created for the VM. vm1 is the stack item name (or the alias of the resource in the blueprint).
  • $(Stack.items[vm1].status) reads the status of the stack item.
Script expression

$(Script:scriptName.function[])

Runtime In the example, VMProperties is a script include with a function called getIP. A script expression is also an example of a complex expression (the expression is nested).

$(Script:VMPropertiesUtil.getIP[ arg=$(Stack.items[VM1].attributes[object_id])])

Expression for Private IP:$(ci.cmdb_ci_nic[$(Script:CMPVMNICs.getNICs[arg=$(Stack.items[Virtual Server].attributes[sys_id])])].private_ip)

Expression for Public IP: $(ci.cmdb_ci_nic[$(Script:CMPVMNICs.getNICs[arg=$(Stack.items[Virtual Server].attributes[sys_id])])].public_ip)

CI lookup expression

$(ci.tableName)

Definitional/Runtime Use to access values of fields in a table, usually a CI table in the CMDB.
  • $(ci.cmdb_ci_cloud_subnet[ sys_id=12231].cidr) dot walks to the Cloud Subnet table, finds the record with the specified sys_id, and takes the value from the cidr column.
  • $(ci.sn_cmp _ip_pool[subnet=${parameter.formData.Subnet Id}]) combines runtime and definition type expressions. The = operator evaluates a value for a match. The expression dot walks to the IP Pool table and looks for the subnet that has the subnet ID that the user submitted.
  • $(ci.cmdb_ci_cloud_subnet[${parameter.formData.SubnetId}].cidr) takes the value of the cidr field from a subnet that the user specified during provisioning. The expression dot walks to the Cloud Subnet table, looks at the subnet value that the user submitted on a blueprint provision, extracts the cidr field value, and then walks to the value in the cidr field of the sys_id of the subnet.
Random number expression

${randomNumber}

Runtime

Generates a random number. For example, you can provision a VM with a random node name or stack name.

You can use this format of expression in policy actions.

${randomNumber}
Scratchpad expression/Resource operation output attribute expression

syntax varies

Runtime Reads output attributes from one operation into another operation.

To set/expose outputs from one operation:

${Compute Interface.CreateNode.Output.resp.nodeId}

To read the output attributes (where VM1.Provision is the operation whose output attributes are read):

$(Outputs[VM1.Provision].NodeId)
Conditions in expressions

syntax varies

Definitional/Runtime You can use conditional expressions in blueprint steps and resource operation steps to conditionally execute or skip the step. The conditional expressions are Javascript expressions and they support expression substitutions.

‘${parameter.CloudAccount}’==’Amazon Cloud Account’

‘$(Stack.items[vm1].attributes[node_id]) ’== ’VM1’

Complex expression

syntax varies

any You can nest expressions. In the example, ${parameter.ServerID} maps the sys_id of the CI and is replaced before the outer expression is consumed.

$(ci.cmdb_ci_vm_instance[${parameter.ServerID}].name)