VoiceXML 2.1 Development Guide Home  |  Frameset Home

  E: VoiceXML Variables  |  TOC  |  Variable Scoping  

Variables


VoiceXML variables follow the standard ECMAscript rules (insert link to ECMA ), and may contain any characters with the exception of the following circumstances:

A variable may NOT begin with an underscore '_', or end with the dollar sign '$' characters. In addition, we may not have a period ‘.' or dash '-' contained within them, ie, the following examples will cause an error.semantic to be thrown:

            <var name="_MyVar"/>
            <var name="MyVar$"/>
            <var name="My.Var"/>
            <var name="My-Var"/>


Variables used for TTS or <log> statements must be defined as string literals to function properly:

            <var name="MyVar" expr="'Eat Canned Ham'"/>
            <log expr="MyVar"/>



Variable Declaration

Nuance VWS2.0 has tightened up a bit in regards to variable declaration. In Nuance VWS 1.3 and Motoroloa platforms, we could get away with this snippet:

<form id="F1">
  <block>
    <assign name="MyVar" expr="'four twenty'"/>
    <prompt> hey, its <value expr="MyVar"/> </prompt>
  </block>


But, when using Nuance VWS 2.0, any variable must be declared before assignation can take place, else an error.badfetch will be thrown:

<form id="F1">
  <block>
  <var name="MyVar"/>
    <assign name="MyVar" expr="'four twenty'"/>
    <prompt> hey, its <value expr="MyVar"/> </prompt>
  </block>


Making a habit out of explicitly declaring all variables will result in code which is much more easily ported across multiple platforms.




  ANNOTATIONS: EXISTING POSTS
pipn
9/14/2006 12:39 PM (EDT)
How can I append data to a variable?

As an example, in C# it would be something like:

Var1 = "Hello";
Var1 = Var1 + " World!";

Results: "Hello World!"

I am trying to do something similar with variables. I have two forms with condition logic. Form1 saves a value to a variable called UpdateText. Then I need Form2 to append a value to the already existing data in the variable UpdateText.

--Form1
<assign name="UpdateText" expr="Hello">

--Form2
<assign name="UpdateText" expr=UpdateText + " World!">

I know that is the wrong syntax but how would I accomplish this?

Thanks
Michael.Book
9/14/2006 3:00 PM (EDT)
Hello All,

The 'expr' attribute value is an ECMAScript expression, so you would use something like:
__________________

--Form1
<assign name="UpdateText" expr="'Hello'">

--Form2
<assign name="UpdateText" expr="UpdateText + ' World!'">
__________________

The single quotes here denote a string value.  Without single quotes references an existing variable.

I hope this helps...


Have Fun,

~ Michael

pipn
9/14/2006 5:23 PM (EDT)
Thanks Michael that fixed it. Another problem I ran in to is trying to pass a variable as a grammar.

As an example, asking the user for their access word to continue. Before asking them I would query a database to get their access word and pass it to a variable. I tried putting the variable in the grammar check but it keeps failing.

<grammar type="text/gsl">
  [(<value expr="AccessWord"/>)]
</grammar>
MattHenry
9/14/2006 7:27 PM (EDT)


Hi there,

To be clear, using VXML variable syntax inside of a grammar is entirely disallowed. I might suggest that you review our tutorial on dynamic grammars to get an idea on how you can isert DB values dynamically into a grammar file:

http://docs.voxeo.com/voicexml/2.0/t_16.htm

~Matt

login

  E: VoiceXML Variables  |  TOC  |  Variable Scoping  

© 2003-2008 Voxeo Corporation  |  Voxeo IVR  |  VoiceXML & CCXML IVR Developer Site