Constants

Constants are scoped like variables, but their values can't be changed through assignment.

Constants have the following properties and restrictions:

  • The scope of a constant can be page, flow, application, or action chain. The value of a constant is defined declaratively in the descriptor using the constants property.
  • The value of a constant can be an expression. The expression can refer to previously-defined constants and variables in the current scope or application/flow.
  • Constants are evaluated first, so expressions in variables can refer to constants.
  • The name of a constant cannot be used by a variable in the same scope.
  • Constants can be used in action chains.
  • A constant can be an input parameter to a page or action chain.
  • A constant cannot be of a built-in type.
  • A constant holds a value that is immutable (contrary to JavaScript). For instance, in the case where the content is an object, this means the object's contents (for example, its properties) cannot be altered.
  • Constants do not dispatch change events, since their values never change.
"constants": {
  "myConstant": {
    "type": "string",
    "description": "A useful constant",
    "defaultValue": "This string"
  }
}

Type

Constant type is the same as for variable except it cannot be a built-in type.

Default Value

Static Default Value. Constants hold a value that is immutable (unlike JavaScript). For instance, in the case where the content is an object, this means the object's contents (for example, its properties) cannot be altered. The value of a constant can be overridden in an extension during initialization, but once the value is set, it cannot be changed. (discussed below).

Dynamic Default Value. A constant's default value can be an expression that contains variables. In this this case, the constant will change when the variable value changes. That change triggers a valueChange event that can be listened to using the onValueChanged property:

"constants": {
  "fullName": {
    "defaultValue": "{{ $variables.firstName + ' ' + $variables.lastName }}",
    "onValueChanged": {
      "chains": [
        {
          "chainId": "fullNameChanged"
        }
      ]
    }
  }
}

Input

Constant input is the same as for variable.

Extension

Like variables, constants can be accessed by downstream or dependent extensions if they are defined in the interface section of the base container.

"interface": {
  "constants": {
    "extendableConstant": {
      "type": "string",
      "description": "A constant visible to extensions",
      "defaultValue": "A string"
    }
  }
}

Additionally, when extending a container with an interface constant, the (base) value of the constant can be changed on the extending container, using the defaultValue property, in the extensions section:

"extensions": {
  "constants": {
    "extendableConstant": {
      "defaultValue": "Value from the extension"
    }
  }
}

Note that the onValueChanged can also be overwritten. In that case, the chain(s) defined in the extension will be invoked instead the one(s) in the base object.