Variable-handling elements

As described in Variables, the <var> element declares a variable, while an <assign> element assigns a new value to an existing variable. Other elements used with variables include:

  • The <clear> element resets one or more variables, including form items. For each variable name you specify in the element’s namelist attribute, that variable is resolved relative to the current scope. For example:

    <clear namelist="PizzaSize PizzaToppings"/>

    This instruction clears the current values of the PizzaSize and PizzaToppings variables, resetting them to an undefined value.

  • The <filled> element contains actions be executed when input items in a given combination are all filled. For example, in the GetPizzaSize form within the GetPizzaSize.vxml document, this element assigns a size to the PizzaSize variable and moves on to the next document once the caller has specified a recognizable pizza size:

    <form id="GetPizzaSize">
      <field name="size">
        <property name="nuance.grammarlabel" value="GetPizzaSize"/>
        <prompt cond="entry == 'init'">
          <audio expr="PromptPath + 'GetPizzaSize_init.wav'"/>
        </prompt>
        <!-- Other possible prompts -->
        <grammar src="../grammars/pizza.grxml#Pizza_Size"/>
        <filled>
          <assign name="PizzaSize" expr="size"/>
          <goto next="GetPizzaToppings.vxml"/>
        </filled>
     </field>
    </form>
  • As discussed under Iteration, the <foreach> element executes content for each item in an array variable.

  • Since VoiceXML variables and ECMAScript variables are interchangeable, you can perform operations on variables within a <script> element.

  • A <value> element displays the current value of a variable as text.

  • Some elements allow you to pass variables from the current document to another document, dialog, or server. See Interacting with a server.

When performing an operation on a variable, remember that its scope affects how the variable can be used. See Variable scope.