large int converting to exponent

Questions and answers about IVR programming for Plum DEV

Moderators: admin, support

  • Author
  • Message
Offline

ljnftw

  • Posts: 6
  • Joined: Mon Oct 30, 2017 10:47 am

large int converting to exponent

PostFri Jan 05, 2018 3:28 pm

I am attempting to receive a large response from the caller. It appears to be received properly but at some point either there or in the JavaScript code is is being expressed exponentially.

Below is the snip of the code where I receive the number then add to an XML packet.

Example:
user enters 12345678901234567890123
JavaScript converts to 1.2345678901234567e+22

Obviously this does not work. I am new to VXML and JavaScript (should be obvious :shock: )

Code snip as follows:

...

<field name="BigNum" type="digits?minlength=15">
<prompt>
Please enter all the numbers that appear on your document, followed by the pound key.
</prompt>
<filled>
<assign name="obj.BigNum" expr="BigNum"/>
</filled>
</field>


...

<form id="verifyDocument">
<var name="obj"/>

<script>
<![CDATA[
function Getdocument(obj)
{
var document = ("<>" +
...
"<>" + obj.BigNum + "</> " +
...
"</>"
);

return document;
}
]]>
</script>
Offline

support

  • Posts: 3456
  • Joined: Mon Jun 02, 2003 3:47 pm
  • Location: Boston, MA

Re: large int converting to exponent

PostMon Jan 08, 2018 11:15 am

Hello!

I'm happy to help. I see some lines code are missing, are you modifying the caller's response mathematically or parsing it into an integer?

Regards,
Plum Support
Offline

ljnftw

  • Posts: 6
  • Joined: Mon Oct 30, 2017 10:47 am

Re: large int converting to exponent

PostMon Jan 08, 2018 11:36 am

support wrote:Hello!

I'm happy to help. I see some lines code are missing, are you modifying the caller's response mathematically or parsing it into an integer?

Regards,
Plum Support

Yes I have left out all code that does not touch the BigNum.

It is a user entered preassigned document number. No modification or parsing of anything.

I really want it received as a string that I am including into an XML packet that will query a database.

It is entered as dtmf. I need the value to match EXACTLY. No Exponentiation and no dropping leading zeros.

I am not totally positive if the exponentiation is occurring in the VXML or when I call the JavaScript code.
Offline

support

  • Posts: 3456
  • Joined: Mon Jun 02, 2003 3:47 pm
  • Location: Boston, MA

Re: large int converting to exponent

PostMon Jan 08, 2018 2:23 pm

Hello,

The code listed below functions to your specifications given the information provided, the variable ("BigNum") received from the VXML will be of type string.

I removed the "obj" variable, if you'd like to create a JavaScript object using the "obj" variable you'll need to define it inside a <script> tag and assign object properties as you would in any other JS environment.

Code: Select all
<?xml version="1.0"?>
<vxml version="2.0">
    <property name="inputmodes" value="dtmf"/>
    <form>
        <field name="BigNum" type="digits?minlength=15">
             <prompt>
                   Please enter all the numbers that appear on your document, followed by the pound key.
             </prompt>
             <filled>
                <assign name="BigNum" expr="BigNum"/>
             </filled>
        </field>
        <block>
             <script>
                 <![CDATA[
                     function Getdocument(){
                         var document = "<>" + "<>" + BigNum + "</>" + "</>";
                         return document;
                     }
                 ]]>
             </script>
             <prompt> value is <value expr="Getdocument()"/> </prompt>
        </block>
    </form>
</vxml>
Offline

ljnftw

  • Posts: 6
  • Joined: Mon Oct 30, 2017 10:47 am

Re: large int converting to exponent

PostTue Jan 09, 2018 9:55 am

support wrote:Hello,

The code listed below functions to your specifications given the information provided, the variable ("BigNum") received from the VXML will be of type string.

I removed the "obj" variable, if you'd like to create a JavaScript object using the "obj" variable you'll need to define it inside a <script> tag and assign object properties as you would in any other JS environment.

Code: Select all
<?xml version="1.0"?>
<vxml version="2.0">
    <property name="inputmodes" value="dtmf"/>
    <form>
        <field name="BigNum" type="digits?minlength=15">
             <prompt>
                   Please enter all the numbers that appear on your document, followed by the pound key.
             </prompt>
             <filled>
                <assign name="BigNum" expr="BigNum"/>
             </filled>
        </field>
        <block>
             <script>
                 <![CDATA[
                     function Getdocument(){
                         var document = "<>" + "<>" + BigNum + "</>" + "</>";
                         return document;
                     }
                 ]]>
             </script>
             <prompt> value is <value expr="Getdocument()"/> </prompt>
        </block>
    </form>
</vxml>

Thanks. It was defined outside the script.

I actually found what appears to be a simpler solution in the JavaScript. Concatenating a null string seem to be working.

I do not see what your solution did that mine did not other than pull BigNum out as it' own variable which would then have to be added BACK into the document variable so it could be processed.

<script>
<![CDATA[
function Getdocument(obj)
{
var document = ("<>" +
...
"<>" + obj.BigNum + '' + "</> " +
...
"</>"
);

Return to Plum DEV Q&A

Who is online

Users browsing this forum: No registered users and 1 guest

cron