| VoiceXML 2.1 Development Guide | Home | Frameset Home |
|
<var name="_myVar"/>
<var name="myVar$"/>
<var name="my.Var"/>
<var name="my-Var"/>
<var> element is equivalent to declaring a variable using client-side scripting within a block of ECMAScript. As such, the two declarations below accomplish entirely the same goal:
<block>
<var name="myVar" expr="'some value'"/>
</block>
<var name="myVar" expr=" ' Eat Canned Ham ' "/>
<log expr="myVar"/>
<form id="F1">
<block>
<assign name="myVar" expr="'four twenty'"/>
<prompt> hey, its <value expr="myVar"/> </prompt>
</block>
<form id="F1">
<block>
<var name="myVar"/>
<assign name="myVar" expr="'four twenty'"/>
<prompt> hey, its <value expr="myVar"/> </prompt>
</block>
| ANNOTATIONS: EXISTING POSTS |
pipn
|
|
| 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
|
|
| 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
|
|
| 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
|
|
|
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 |
|
mframpton
|
|
| I see that "A variable may NOT ... have a period '.' or dash '-' contained within them".
Unfortunately, I'm integrating with a system which relies on some variables of the format "Qn-n-nnnnnnnnn" to identify question numbers and I have no control over this format. If I declare a var with a name like 'Q1-1-7268742', I get a gateway error. Do you see any workaround for this? |
|
VoxeoDustin
|
|
| Hey,
You may be able to workaround this with a bit of server-side coding. You'd need to submit the data to a server-side script that would convert the variables to the syntax you need and send the request to your backend API from within the server-side. Regards, Dustin Hayre Customer Support Engineer 2 Voxeo Support |
|
mframpton
|
|
| Thanks Dustin, I now have that working OK.
For anyone that's interested, code fragements are like this (I'm building up the html string to create the page): html.append("<var name=\"QID\" expr=\"'" + qid.replace("-","_") + "'\"/>"); html.append("<submit next=\"redirect2.jsp\" namelist=\"QID ANS\"/>"); and then within redirect2.jsp <% String qid = (String)request.getParameter("QID"); String mqid = qid.replace("_","-"); String ans = (String)request.getParameter("ANS"); %> <jsp:forward page="theRealURL.jsp" > <jsp:param name="<%=mqid%>" value="<%=ans%>" /> </jsp:forward> |
|
voxeoJeffK
|
|
| Hello,
Thank you for including that. We, and future developers thank you. regards, Jeff Kustermann Voxeo Support |
|
eman.elsawa
|
|
| Hello
Hoow could i assign the variable a value that was taken from a field.I mean if the user speaks a number ,i need to assign this variable he number that was spoken Regards Eman |
|
mikethompson
|
|
| Hello Eman,
The field name (<field name="MyField">) actually contains the matched utterance result from the grammar. However, if you want to access the slot value returned from the grammar, you'll need to access the interpretation variable like so: lastresult$.interpretation.MyField We have more information on how to do this in our documentation: http://www.vxml.org/grxmlslots.htm Hope this helps, Mike Thompson Voxeo Corporation |
|
herocksit
|
|
| What is the significance of '$' in "lastresult$"? Is it not possible to access without '$'?
|
|
jdyer
|
|
| Hello,
It's my understanding that you are asking about the significance of the $, and whether or not it is able to be omitted, is this correct? If this is the case then I am afraid the answer is no, as this is the syntax for shadow variables (http://www.vxml.org/t_13.htm?search=shadow) in the VoiceXML markup. Might we ask what you are trying to accomplish here, do you have a need to remove this character from your code? Please do advise, as our team is most certainly standing by to be of service! Regards, John Dyer Customer Engineer Voxeo Support |
|
Hixxey
|
|
| Is it possible to make a variable global? So that when I go to another file such as a getPrices.JSP the varible will still have data within it when I return to the main.vxml.
Also, is it possible to store a recorded voice to a simple .mp3 or .wav? Thanks, Hixxey |
|
voxeoJeffK
|
|
| Hello,
If you specify a root document in a leaf file using the application attribute: <vxml version = "2.1" application="AppRoot.vxml"> all event handlers, variables, links, grammars, and scripts contained within the root document are considered active when each document loads. All variables declared within the root document are then considered to have application scope, and are available at any point in the application. To access or write to application scoped variables you will want to use the naming syntax of "application.VarName" Concerning recording, you can record a user, utterance, or complete call. We have details available here: http://www.vxml.org/recording.htm Please let us know if we can help with any other questions or clarifications. Regards, Jeff Kustermann Voxeo Support |
|
Hixxey
|
|
| Thanks for that. I've now got the variable working and I will look over the recording section tomorrow.
I forgot to ask if it is possible and if so how can I write from a variable to a text file (test.txt) Thanks, Hixxey |
|
VoxeoDante
|
|
| Hello,
There is nothing in VoiceXML directly that will be able to write a variable to a file, but you should be able to do it with some serverside. Here is a little PHP example that should be able to write the value of a variable called "name" that you pass to it into a text file called testFile.txt. [code] <? $stringData = $_REQUEST["name"]; $myFile = "testFile.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, $stringData); fclose($fh); ?> [/code] I hope this helps. Regards, Dante Vitulano Customer Support Engineer II Voxeo Corporation |
|
N0182209
|
|
| hi there,
i trying to call a jsp file from my main vxml program, i have the code below be once directed to the form the phone just goes quiet, i wondered if the code im using is correct, any help would be appreicate. <form id="test"> <filled> <submit next="salesec.jsp"/> </filled> </form> |
|
jdyer
|
|
| Hello,
Is this sample code snippet complete, or just illustrative? If this is the actual offending code block then the issue is most likly that you have filled as a child of form, which is not valid. You can wrap the submit in a block, which is a proper child of form. If you are still having issues please submit logging from the log viewer, or application debugger so we can review the actual call flow. The application debugger is the best diagnostic tool that we have for getting insight into applications that aren't behaving the way we want them to, but it takes a bit of experience to intuit the messages displayed. Click on the "account" tab at the top right of evolution site, and select the "application debugger" prior to making test calls to capture the data. You can then select the "support" tab in the debugger to send us a problem report. Some additional links on this utility are provided below: http://docs.voxeo.com/voicexml/2.0/loggerfeatures.htm http://docs.voxeo.com/voicexml/2.0/mot_loggermessages.htm http://docs.voxeo.com/voicexml/2.0/gettingsupport.htm Hope this helps, and we are standing by for your update at this time. Regards, John Dyer Customer Engineer Voxeo Support |
|
futurejp
|
|
| Hi, I have a question. I have an array variable and a counter variable. So if I want to get the value inside certain cell of an array, I can say in a prompt
<value expr="gameListAudio[qCounter]"/> and it will speak the value, currently either the string "easy" or "hard". I want to put this in a conditional and I feel like I've tried every possible way but nothing works. So I want to say something like: <if cond="gameListAudio[qCounter] == 'easy'"/> <audio src="audio/easy.wav"/> <else/> <audio src="audio/hard.wav"/> ... Which doesn't work. No audio plays. The audio is there, because if I say <audio src="audio/hard.wav"/> outside of a conditional, it plays. I've tried doing things like <if cond="value expr='gameListAudio[qCounter]' == 'easy'"/> to try to get at the *value* of that array cell, but nothing seems to work. Any ideas? Also, here's another question. Say I just have a variable myVar and its value is either 'hard' or 'easy.' Is there a way for me to say something like: <audio src="audio/" + myVar + ".wav"/> ? Because that would be very helpful. Thanks. |
| login |
|