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

Global variable in Root doc reinitializing

Questions and answers about IVR programming for Plum DEV

Moderators: admin, support

Post Reply
mriv
Posts: 5
Joined: Thu Apr 14, 2016 11:41 am

Global variable in Root doc reinitializing

Post by mriv »

Hello. I am trying to follow the documentation on Root documents in order to catch events and submit useful data for troubleshooting to a database. My Root document contains a variable (<var name="StepData" expr="'Start'" />) that is appended to throughout the child document. The Root document also has a catch of the event connection.disconnect. In this catch, data (connection.disconnect) is appended to the StepData variable and a submit sends the data so it is logged in a database. If I successfully complete a call to the <disconnect/> tag in the child document, all the expected data is successfully logged in the database. The problem is if I hang up prior to reaching the disconnect tag. In this case, all the data between Start and connection.disconnect is lost. It appears as if the catch event of connection.disconnect in the Root document is causing the StepData variable to be reinitialized to the value Start. I have log statements throughout the child document that shows the data is successfully appending to the StepData variable prior to the connection.disconnect event. What am I missing? I appreciate any assistance you can provide.

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

Re: Global variable in Root doc reinitializing

Post by support »

Hello mriv,

Would you be able to supply us with code so we may further assist you.

Regards,
Plum Support

mriv
Posts: 5
Joined: Thu Apr 14, 2016 11:41 am

Re: Global variable in Root doc reinitializing

Post by mriv »

Below is the code. I appreciate any assistance you can provide.

For a call that reaches the disconnect tag, the data logged to the database is complete (Start|addData1|addData2|addData3|input|addData4|addData5|disconnect), but for a call with a hang up at the prompt for input, the data logged to the database is not complete (Start|connection.disconnect). The log messages for both types of calls are:
Complete log messages
application.StepData= Start
application.StepData= Start|addData1
application.StepData= Start|addData1|addData2
application.StepData= Start|addData1|addData2|addData3
application.StepData= Start|addData1|addData2|addData3|input
application.StepData= Start|addData1|addData2|addData3|input|addData4
application.StepData= Start|addData1|addData2|addData3|input|addData4|addData5
application.StepData= Start|addData1|addData2|addData3|input|addData4|addData5|disconnect
application.StepData= Start|addData1|addData2|addData3|input|addData4|addData5|disconnect|connection.disconnect

Hang up at the input prompt the log messages
application.StepData= Start
application.StepData= Start|addData1
application.StepData= Start|addData1|addData2
application.StepData= Start|addData1|addData2|addData3
application.StepData= Start|connection.disconnect

Start.xml
-----------
<?xml version="1.0"?>
<vxml version="2.0">
<script>
function GetFormattedDateTime()
{
var dt = new Date();
var dtstring = dt.getFullYear()
+ '-' + (dt.getMonth()+1)
+ '-' + dt.getDate()
+ ' ' + dt.getHours()
+ ':' + dt.getMinutes()
+ ':' + dt.getSeconds();
return dtstring;
}
</script>
<var name="startTime" expr="GetFormattedDateTime()" />
<var name="endTime" />
<var name="url" expr="'http://x.x.x.x/myloggingpage.aspx?'" />
<var name="Process" />
<var name="IVRCallData" expr="session.id+'^'+session.telephone.ani+'^'+session.telephone.dnis" />
<var name="StepData" expr="'Start'"/>
<form>
<block>
<log label="mylog">application.StepData= <value expr="application.StepData"/></log>
<log label="mylog">Goto Child.xml</log>
<goto next="Child.xml"/>
</block>
</form>
<!-- Catch events -->
<catch event="connection.disconnect">
<assign name="application.StepData" expr="application.StepData+'|connection.disconnect'" />
<log label="mylog">application.StepData= <value expr="application.StepData"/></log>
<assign name="endTime" expr="GetFormattedDateTime()" />
<assign name="Process" expr="'IVRLogCallData'" />
<assign name="IVRCallData" expr="IVRCallData+'^'+startTime+'^'+endTime+'^'+application.StepData" />
<submit expr="url" namelist="Process IVRCallData"/>
</catch>
</vxml>


Child.xml
------------
<?xml version="1.0"?>
<vxml version="2.0" application="Start.xml">
<form>
<block>
<prompt>This is a test application.</prompt>
<assign name="application.StepData" expr="application.StepData+'|addData1'" />
<log label="mylog">application.StepData= <value expr="application.StepData"/></log>
<prompt>Appended data one</prompt>
</block>
<block>
<assign name="application.StepData" expr="application.StepData+'|addData2'" />
<log label="mylog">application.StepData= <value expr="application.StepData"/></log>
<prompt>Appended data two</prompt>
</block>
<block>
<assign name="application.StepData" expr="application.StepData+'|addData3'" />
<log label="mylog">application.StepData= <value expr="application.StepData"/></log>
<prompt>Appended data three</prompt>
</block>
<subdialog name="custID" src="#customerIDForm" />
<block>
<if cond="custID.response==0">
<assign name="application.StepData" expr="application.StepData+'|noInput'" />
<log label="mylog">application.StepData= <value expr="application.StepData"/></log>
<prompt>You did not provide input</prompt>
<else/>
<assign name="application.StepData" expr="application.StepData+'|input'" />
<log label="mylog">application.StepData= <value expr="application.StepData"/></log>
<prompt>Thank you for the input</prompt>
</if>
</block>
<block>
<assign name="application.StepData" expr="application.StepData+'|addData4'" />
<log label="mylog">application.StepData= <value expr="application.StepData"/></log>
<prompt>Appended data four</prompt>
</block>
<block>
<assign name="application.StepData" expr="application.StepData+'|addData5'" />
<log label="mylog">application.StepData= <value expr="application.StepData"/></log>
<prompt>Appended data five</prompt>
</block>
<block>
<assign name="application.StepData" expr="application.StepData+'|disconnect'" />
<log label="mylog">application.StepData= <value expr="application.StepData"/></log>
Going to disconnect. Good bye.
<disconnect/>
</block>
</form>

<form id="customerIDForm">
<property name="inputmodes" value="dtmf"/>
<property name="termmaxdigits" value="true"/>
<property name="interdigittimeout" value="3s"/>
<!-- Prompt for input -->
<field name="customerid" type="digits?minlength=7">
<prompt>
Please enter your account number.
</prompt>
<nomatch>
<goto next="#customerIDForm" />
</nomatch>
<noinput>
You did not enter anything.
<goto next="#customerIDForm" />
</noinput>
</field>
<!-- Repeat back-->
<block>
<prompt>
You entered
<say-as type="number:digits">
<value expr="customerid.replace(/(.)/g, '$1, ')" />
</say-as>
</prompt>
<assign name="response" expr="customerid" />
</block>
<!-- Confirm -->
<field name="OK" type="boolean">
<prompt>
If this is correct, press one, if not, press two.
</prompt>
<filled>
<if cond="OK==false">
<goto next="#customerIDForm" />
</if>
</filled>
<nomatch>
<goto next="#customerIDForm" />
</nomatch>
</field>
<!-- Success -->
<block>
<return namelist="response"/>
</block>
</form>
</vxml>

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

Re: Global variable in Root doc reinitializing

Post by support »

Hi Mriv,

The issue lies in the use of the subdialog tag in your Child.xml script. When you use a subdialog within the same document what it essentially does is create an anonymous scope for that subdialog that gets a copy of the root variables at the start of the script, so the value of StepData when entering the subdialog would be 'Start'. So if you hang up while in this subdialog, that's why you're getting 'start|connection.disconnect'. Luckily there's no need to use a subdialog here, so you can use the normal form/field and gotos to accomplish the same end. We've modified your Child.xml script to use a goto to enter the account number input form and then continue with the same script afterwards with another goto. This eliminates the subdialog anonymous scope and will retain the StepData from the root document for the entire duration of the Child.xml script, such that your connection.disconnect catch block will always get the updated StepData.

Code: Select all

<?xml version="1.0"?>
<vxml version="2.0" application="Start.xml">

<property name="documentmaxage" value="0s"/>
<property name="documentmaxstale" value="0s"/>

<form>
<block>
<prompt>This is a test </prompt>
<assign name="StepData" expr="StepData+'|addData1'" />
<log label="mylog">StepData= <value expr="StepData"/></log>
<prompt>Appended data one</prompt>
</block> 
<block>
<assign name="StepData" expr="StepData+'|addData2'" />
<log label="mylog">StepData= <value expr="StepData"/></log>
<prompt>Appended data two</prompt>
</block> 
<block>
<assign name="StepData" expr="StepData+'|addData3'" />
<log label="mylog">StepData= <value expr="StepData"/></log>
<prompt>Appended data three</prompt>
<goto next="#customerIDForm"/>
</block>
</form>

<form id="continue">
<block>
<assign name="StepData" expr="StepData+'|addData4'" />
<log label="mylog">StepData= <value expr="StepData"/></log>
<prompt>Appended data four</prompt>
</block> 
<block>
<assign name="StepData" expr="StepData+'|addData5'" />
<log label="mylog">StepData= <value expr="StepData"/></log>
<prompt>Appended data five</prompt>
</block> 
<block>
<assign name="StepData" expr="StepData+'|disconnect'" />
<log label="mylog">StepData= <value expr="StepData"/></log>
Going to disconnect. Good bye.
<disconnect/>
</block>
</form>

<form id="customerIDForm">
<property name="inputmodes" value="dtmf"/>
<property name="termmaxdigits" value="true"/>
<property name="interdigittimeout" value="3s"/>
<!-- Prompt for input -->
<field name="customerid" type="digits?minlength=7">
<prompt>
Please enter your account number.
</prompt>
<nomatch>
<goto next="#customerIDForm" />
</nomatch>
<noinput>
You did not enter anything.
<goto next="#customerIDForm" />
</noinput>
</field>
<!-- Repeat back-->
<block>
<prompt>
You entered
<say-as type="number:digits">
<value expr="customerid.replace(/(.)/g, '$1, ')" />
</say-as>
</prompt>
<assign name="response" expr="customerid" />
</block>
<!-- Confirm -->
<field name="OK" type="boolean">
<prompt>
If this is correct, press one, if not, press two.
</prompt>
<filled>
<if cond="OK==false">
<goto next="#customerIDForm" />
<else/>
<assign name="StepData" expr="StepData+'|input'" />
<log label="mylog">StepData= <value expr="StepData"/></log>
<prompt>Thank you for the input</prompt> 
<goto next="#continue"/>
</if>
</filled>
<nomatch>
<goto next="#customerIDForm" />
</nomatch>
</field>
<!-- Success -->
<block>
<return namelist="response"/>
</block>
</form>
</vxml>
Hopefully that helps, but please let us know if you have any questions.

Regards,
Plum Support

mriv
Posts: 5
Joined: Thu Apr 14, 2016 11:41 am

Re: Global variable in Root doc reinitializing

Post by mriv »

Thanks for the quick response. I do have a follow up question. If I were to move the form customerIDForm into a separate document, could I use subdialog and still maintain the scope?

mriv
Posts: 5
Joined: Thu Apr 14, 2016 11:41 am

Re: Global variable in Root doc reinitializing

Post by mriv »

Hi. I decided to give it a try. Moving it to another document does not maintain the scope either. Thanks.

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

Re: Global variable in Root doc reinitializing

Post by support »

Hi Mriv,

Yes, you are correct, that would not make a difference as the subdialog would still have an anonymous scope, which would be a copy of the StepData global variable from the start of Child.xml. You can use subdialogs as separate scripts, but the same scoping rules still apply. Generally what you'd want to do with a subdialog is to pass in the variables and return it back from the subdialog, but not directly modifying any global variables within your subdialogs.

Regards,
Plum Support

Post Reply