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

ecmascript error on substr attempt

Questions and answers about IVR programming for Plum DEV

Moderators: admin, support

Post Reply
vmagic
Posts: 14
Joined: Tue Aug 08, 2006 3:20 pm

ecmascript error on substr attempt

Post by vmagic »

I want to use substr to pick off the "3" in "13" contained in "quizno" & use it as an index to retrieve & speak the value "four" from the array.

I am getting the following error...

VXI::var_element(name="quiz_ans" expr = "subd.myarray[quizno.substr(1)]")
errmsg TypeError: quizno.substr is not a function line 1 linetxt tokentxt
received event: error.semantic.ecmascript

Code: Select all

<?xml version="1.0"?>
<vxml version="2.0">
     
        <form id="caller">
                <var name="quizno" expr="13"/>
                <subdialog name="subd" src="#callee">

                </subdialog>
                <block>
                <var name= "quiz_ans" expr="subd.myarray[quizno.substr(1,1)]"/>

                 <prompt>
                               You entered 
                 <say-as type="acronym">
                <value expr="quiz_ans"/>
                  </say-as>         
                  </prompt>      
                </block>
        </form>
        <form id="callee">
                <var name="myarray"/>
                <script>
                        myarray = new Array(4);
                        myarray[0] = 'one';
                        myarray[1] = 'two';
                        myarray[2] = 'three';
                        myarray[3] = 'four';
                 </script>
                <block>
                        <return namelist="myarray"/>
                </block>
        </form>
</vxml>

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

IVR code needs quotes around text to convert value to string

Post by support »

Hello,

This IVR error is occuring because you are initializing quizno to the number 13, not the string "13". You should add single quotes around text in the expr attribute of the <var> tag to convert the value into a string:

Code: Select all

<var name="quizno" expr="'13'"/>
After forcing quizno to be initialized as a string you should be able to make use of the substr() method available to all strings.

Regards,
Plum Support

Post Reply