Var and Assign Elements

Use

The variable element var is used to define a VoiceXML variable. The variable’s value is defined with its Initial Value Expression attribute, or an assign element.

If the variable must be available globally for all IVR elements, define it directly in the vxml heading: right-click Start IVR and choose var. We recommend defining global variables as first elements in an IVR, they are easy to find and be referred to.

The variables defined upper than other elements in the document, appear with a prefix var: in the selection list for those other elements’ attribute conditions and expressions. If you define the variable later on, it is placed as the last element in the IVR document; to move it up, choose the element and click Up as many times as required.

Var

The variable element var is used to declare a variable within the scope specified by its parent element.

The var element can be nested in the following parent elements: block, error, field, filled, form, if, nomatch, timeout. It cannot have child elements.

* = Specific to Sinch Contact Center

Attributes for var Element

Description

Name

Mandatory. Enter a short descriptive name. Use letters a-z, A-Z, numbers, and underscore (_), only. After the element attributes are saved, the name appears in the ID column.

The Name appears also with the prefix var: in the condition and expression drop-down lists of the elements of same scope (if the variable is global, this applies to all elements).

If you use the assign element to declare the variable value, you may leave other attributes undefined.

Initial Value Expression

Choose or enter the expression that defines the variable’s initial value. The expression can be either a string, or a Python dictionary.

For a string, enter it with one of the ways:

  • Enter it directly, such as 12345.

  • Use a predefined expression template:

    1. Select the template from the drop-down list.

    2. Select x (and y) from the drop-down list, or write the value, variable, or Python statement.

    3. Click OK.

  • Choose an expression from the drop-down list, and complete the Python statement, if needed.

  • Enter the whole expression in Python code.

To enter a Python dictionary, enter dictionary data in key/value pairs in Key and Value fields, and add it to dictionary with the plus (+) button. To remove a key/value pair from the dictionary, choose the pair and click the minus (-) button.

Initial Value as Dictionary Data

To define the variable’s initial values as key/value pairs, enter them in Key and Value fields, and add each pair to dictionary with the plus (+) button.

To remove a key/value pair from the dictionary, choose the pair and click the minus (-) button.

To change the row order, choose the row, and move it with the Up and Down buttons.

Description*

Enter a description of your element; what is it planned for, its requirements and limitations.

Assign

The assign element can be nested in the following parent elements: block, error, filled, if, noinput, nomatch, timeout. It cannot have child elements.

Attributes for assign Element

Description

Target Variable

Choose from the list the variable to which you want to assign a value.

Value Expression

Define the expression for the variable’s value with one of the following ways:

  • Enter the value directly. For example, to assign to the variable queue_number a specific queue number, enter numbers '12345', remember to use quotes.

  • Choose a query or variable from the drop-down list, and complete the Python statement, if needed. For example, to make an expression where the A-number is the data source as such, choose {ANUMBER} from the list.

  • Use a ready-made expression:

    1. Select the template from the drop-down list.

    2. Select x (and y) from the drop-down list, or write the value, variable, or Python statement.

    3. Click OK.

    For example, to make an expression where the last 4 numbers of the caller’s number are required, choose Expression: Last ’Y’ Characters of String ’X’, and choose {ANUMBER} from the list for X, and for Y enter the number 4.

  • Enter the whole expression in Python code. The example above can be entered as str({ANUMBER})[4:].

Value as Dictionary Data

To define for a variable values as key/value pairs, enter them in Key and Value fields, and add each pair to dictionary with the plus (+) button.

To remove a key/value pair from the dictionary, choose the pair and click the minus (-) button.

To change the row order, choose the row, and move it with the Up and Down buttons.

Description*

Enter a description of your element; what is it planned for, its requirements and limitations.

Example

Have a look at the menu example in the Examples and Templates folder.

There is a global variable queue_number defined with a var element, no other attributes are defined but the Name. To define the variable values, there is the form element with the id set_queue_numbers, it includes the following elements:

  • block with the condition that menu item 1 is selected

    • assign with the following attribute definitions:

      • Target Value has the value queue_number

      • Value Expression should be the queue number that corresponds to the menu selection 1.

  • block with the condition that menu item 2 is selected

    • assign with the following attribute definitions:

      • Target Value has the value queue_number

      • Value Expression should be the queue number that corresponds to the menu selection 2.