We've Moved! Please visit our new and improved forum over at our new portal: https://portal.plumvoice.com/hc/en-us/community/topics

How to just get data back into the xml from a submit.

Questions and answers about IVR programming for Plum DEV

Moderators: admin, support

Post Reply
always24x7
Posts: 30
Joined: Tue Apr 18, 2006 3:05 pm
Location: Bedford, TX

How to just get data back into the xml from a submit.

Post by always24x7 »

The example on the tutorial page for Server Side Dynamics shows a whole form being used. When it returns from that form, if you don't have a <goto> tag specified, the script exits. If you do have a <goto> tag, it appears to require that it be fully qualified. This means that you would have to go to another form when it returns.

Is there a way to have the the server side just output some JavaScript (ECMAScript) such that some variables will be set in the form that did the submit and the script continues at the location in the script right after the submit tag?

Current running form:
===============

<form id="some_form">
<var name="action">
<block>
<assign name="action" expr="'search'"\>
<submit next="getData.php" namelist="action" method="post"/>
<if cond="result==1>
<prompt>
Welcome <value ="first_name"\>
</prompt>
<else>
<prompt>
Sorry, could not find your record.
</prompt>
</if>
</block>
</form>

Server Side output:
==============

<?xml version=\"1.0\"?>
<script>
var first_name = 'John';
var last_name = 'Doe';
var result = 1;
</script>

support
Posts: 3632
Joined: Mon Jun 02, 2003 3:47 pm
Location: Boston, MA
Contact:

IVR examples of data tag use in VoiceXML 2.1 specifications

Post by support »

Hello,

Generally VoiceXML scripts are programmed in a way that is similar to a web page. You have a form with one or more fields, when all the fields have been filled in the IVR script performs a page transition via submit. The page that is submitted to performs a database look up and presents more data and collects more information from the user.

If you do not wish to perform a complete page transition and are instead attempting to do something similar to AJAX you can make use of the new VoiceXML 2.1 feature the <data> tag. This can allow for less data to be transmitted between the Plum IVR system and your IVR application server, but requires considerably more ECMAScript knowledge and can be harder to debug. You can find some IVR examples of the use of the data tag in the VoiceXML 2.1 specification. http://www.w3.org/TR/voicexml21/#sec-data

Regards,
Plum Support
Last edited by support on Thu Feb 25, 2010 2:05 pm, edited 3 times in total.

always24x7
Posts: 30
Joined: Tue Apr 18, 2006 3:05 pm
Location: Bedford, TX

Getting data back from a <data> tag problem.

Post by always24x7 »

O.K.

I am about to go nuts now. I have tried to follow every example I can find, including the one on w3c, and each has its own quirks. Particularly their complexity.

I chose the following off of the w3c as it was the simplest example.
===============================================

w3c data:
=======
<?xml version="1.0" encoding="UTF-8"?>
<quote>
<ticker>F</ticker>
<name>Ford Motor Company</name>
<change>1.00</change>
<last>30.00</last>
</quote>

w3c code:
=======

<data name="quote" src="quote.xml"/>
<script>
<![CDATA[
var price = quote.documentElement.getElementsByTagName("last").item(0).firstChild.data;
]]>
</script>


My code looks like:
=============
<form>
<block>
<data name="domResult" namelist="action" src="http://www.somedomain.com/ivr/
getData.phtml" method="post"/>

<script>
<![CDATA[
//-------------------------------------
// Following code is the equivalent of the example code
//-------------------------------------
/*
var data= domResult.documentElement.getElementsByTagName("name").item
(0).firstChild.data;
*/

//---------------------------
// This code is just to break it apart a little
//---------------------------
var result = domResult.documentElement;
var names = result.getElementsByTagName("name");
var item = names.item(0);
// Use this line to check just the tag name
// data = item.nodeName;
// Use this line to show that the EMACS script is working.
// data = "Edward Baer";
data = item.data;
]]>
</script>

<prompt>
I got <value expr="data"/> back from the Server side query.
</prompt>
<goto next="#card_balance"/>
</block>
</form>

Here is my data:
===========
<?xml version="1.0" encoding="UTF-8"?>
<data>
<name>Edward Baer</name>
<result>1</result>
</data>

If I use the line that explicitly sets data = "Edward Baer", the IVR system says "Edward Baer".

If I use the line that sets data = item.nodeName, the IVR system says "name".

If I use the line that sets data = item.data, the IVR system says nothing.

If I set data = item.firstChild.data, the IVR system says nothing.

If I set data = item.item(0).data, the IVR gives a semantic error.

What am I doing wrong?

support
Posts: 3632
Joined: Mon Jun 02, 2003 3:47 pm
Location: Boston, MA
Contact:

idiosyncrasies of IVR platform's DOM implementation

Post by support »

Hello,

First of all you probably should avoid the <data> tag unless you have some very obvious reason for using it. Standard page transitions are the much more traditional way to implement a VoiceXML script for a reason, they are far easier to debug. Without considerable experience dealing with ECMAScript DOM parsing and a good understanding of the idiosyncrasies of our IVR platform's DOM implementation, debugging is going to be a lot of work for you. The following IVR code worked when we tested it:

Code: Select all

<?xml version="1.0"?>
<vxml version="2.0">
<property name="inputmodes" value="dtmf"/>
<form id="form1">
	<block>
		<var name="action" expr="'asdf'"/>
		<data name="domResult" namelist="action" src="action.php" method="post"/>
		<script>
			var result = domResult.documentElement;
			var names = result.getElementsByTagName('name');
			var item = names.item(0);
			data = item.firstChild.data;
		</script>
		<prompt>
			I got <value expr="data.toString()"/> back from the Server side query.
		</prompt>
	</block>
</form>
</vxml>
The above IVR code assumes that the XML will come back as:

Code: Select all

<?xml version="1.0"?>
<data>
<name>Edward Baer</name>
<result>1</result>
</data>
It is possible that referencing the data as data.toString()might solve your problem since that was the only obvious difference between our two versions. This was necessary to force the conversion from a DOM Text Object to a standard ECMAScript String. Hope this helps.

Regards,
Plum Support
Last edited by support on Thu Feb 25, 2010 2:06 pm, edited 2 times in total.

always24x7
Posts: 30
Joined: Tue Apr 18, 2006 3:05 pm
Location: Bedford, TX

Post by always24x7 »

Actually, you are correct about the toString(). After about 12 hours of fighting this, I accidentally determined that if I prepended a string constant, (even a blank one), in the assignment of the data member, I could get the data out. If not, I got a "Serious Error, symantic" something or other.

I actually did think about doing this all via PHP pages, but the main problem with that was a concern of latency for having to access a PHP for the vxml which then had to access another page (on a different server) for the data. Also, I am new to vxml, so I have not yet assimilated to the architecture/paradigm.

With just a few small ECMAScript routines, I was able to easily navigate the DOM object returned. So, debugging may still be an issue, but getting the data no longer is.

Post Reply