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

Undefined variable in Javascript?

Questions and answers about IVR programming for Plum DEV

Moderators: admin, support

Post Reply
srmoser430
Posts: 20
Joined: Thu Oct 19, 2017 3:40 pm

Undefined variable in Javascript?

Post by srmoser430 »

Hi Folks,

I can't figure out why the variable highlighted in red is undefined within the script. Your help is very much appreciated.

Thanks...Scott

<vml ...
<vxml ....

<var name="invitation_code"/>

<form id="invitation">

<field name="inv_code" type="digits?length=8">
<prompt bargein="false">
We sent you an invitation email. Please enter your unique 8 digit invitation code included in this email.
</prompt>
<filled>
<assign name="invitation_code" expr="inv_code"/>
</filled>
<noinput count="1">
<prompt bargein="false">
Sorry, I didn't hear you.
</prompt>
<reprompt/>
</noinput>
<noinput count="2">
<prompt bargein="false">
You did not enter anything. Your unique 8 digit invitation code is included in your invitation email. Please enter it now.
</prompt>
<reprompt/>
</noinput>
<noinput count="3">
<prompt bargein="false">
You seem to be having some trouble. Please contact our support team at the telephone number included in your invitation email.
</prompt>
</noinput>
</field>
<block>
<log label="scottlog">
inv_code is <value expr="inv_code"/> invitation_code is <value expr="invitation_code"/>
</log>
</block>
<!-- call API to verify invitation code and request activation code -->
<script>

// <![CDATA[

var json_data = new Object();

json_data.orgid = String(orgid);
json_data.action = "get";
json_data.cid = invitation_code;

var json_string= JSON.stringify(json_data);

// ]]>

</script>

<block>
<log label="scottlog">
JSON data is <value expr="json_string"/>
</log>
</block>

</form>

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

Re: Undefined variable in Javascript?

Post by support »

Hello,

The issue is the order in which your code is being executed. Each time a new scope is executed all of the ECMAScript elements are executed in the order they appear at that scope. So your script would do the following:

1. create the "invitation_code" variable (as undefined).
2. load the "invitation" form.
3. create the "inv_code" variable (as (undefined).
4. the <script> code block is executed.
5. the "inv_code" field is executed.
6. each of the <block> sections are executed in document order.

In order to get the <script> to execute after the <field> you can move it into one of the <block> sections that are after the <field> tag.

Regards,
Plum Support

Post Reply