1

My aim is to log a JSON object value fethed from a jsp file from the vxml. Is there any way to do that. I see that there is a function called JSON.stringify but thats giving me nothing as a log. Below is my code:

<?xml version="1.0"?>
<vxml version="2.0" xmlns="http://www.w3.org/2001/vxml">

        <var name="userId" expr="1" />
        <!--form id="get_location"-->
                        <data name="userData" method="get" src="http://localhost:5000/userLocation.jsp" nameList="userId" />

                <property name="inputmodes" value="dtmf"/>
                <menu id="menuZero">
                <choice dtmf="1" next="#choice1"/>
                 <choice dtmf="2" next="#choice2"/>

                 </menu>
        <!--/form-->
<form id="choice1">
        <block>
                <if cond="userData.HttpResponse.do_queryResponse[&apos;return&apos;].errorMsg.result_code != &apos;0&apos;">
                                                <goto next="welcome.vxml"/>
                                                                                 <else/>
                                                                                                                  <goto next="welcome.vxml"/>
                                                                                                                                                   </if>
  </block>
  </form>
  <form id="choice2">
          <block>
 <log expr="JSON.stringify(userData.HttpResponse)"/>
          </block>

                                                                                                                                                                                                                                                                                                                                                               </form>
</vxml>
user2349990
  • 386
  • 4
  • 19
  • possible duplicate of [Spring - web pages using XSLT](http://stackoverflow.com/questions/5133375/spring-web-pages-using-xslt) – Paul Sweatte Jan 28 '14 at 23:51

2 Answers2

2

Maybe, VoiceXML is not supported "JSON.stringify". Try to get "json2.js" and add code.

<script src="json2.js" />

For example,

<?xml version="1.0" encoding="UTF-8"?>
<vxml
    version="2.0"
    xmlns="http://www.w3.org/2001/vxml"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >

    <script src="json2.js" />

    <var name="messageObject" expr="{keyA:'valueA',keyB:'valueB',keyC:'valueC'}" />

    <form>
        <block><prompt>Write Log!</prompt></block>
        <block><log expr="JSON.stringify(messageObject)"/></block>
    </form>

</vxml>

I tested this code on "Voxeo Prophecy 13".

Bladean Mericle
  • 524
  • 2
  • 13
  • Should i include any other file aprt from json2.js because im getting this error "Assignment to undeclared variable JSON (-#162) " – user2349990 Sep 24 '13 at 05:12
  • I further checked your code and found few problem. 1 - data element is not supported VoiceXML 2.0. It is supported VoiceXML 2.1 later. 2 - data element is not supported JSON. It can to use XML only. 3 - [DOM's Docment object](http://www.w3.org/TR/DOM-Level-2-Core/ecma-script-binding.html) have not "HttpResponse". – Bladean Mericle Sep 24 '13 at 06:05
0

I tried json2.js as described above and I had the same issue, 'assignment to undeclared variable JSON'. To fix this, I just declared in the same file (json2.js):

var JSON;

Then it worked properly. In the vxml:

<script><![CDATA[
     prueba = new Object();
     prueba.pepito = 1234;
     prueba.OtraPrueba = "lalalapepe";
]]></script>
     <log label="IVB_HISTORY">
         <value expr="JSON.stringify(prueba)"/>
     </log>

It gets logged as followed:

{"pepito":1234,"OtraPrueba":"lalalapepe"}

I'm using Convergy's InVision Studio