3

I have wrote this basic voiceXML application, but I am stuck for hours on a basic flow control issue. The goto tag (<goto nextitem="countryState" />) does not work. I keep staying in the loop for variable name offset. Any help would be great.

Thanks in advance.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE vxml PUBLIC "-//BeVocal Inc//VoiceXML 2.0//EN" "http://cafe.bevocal.com/libraries/dtd/vxml2-0-bevocal.dtd">
<vxml xmlns="http://www.w3.org/2001/vxml" xmlns:bevocal="http://www.bevocal.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0">
    <form>
        <field name="offset">
            <grammar src="map.xml#cities" type="application/grammar-xml"/>
            <prompt>
                What city would you like the time for?
            </prompt>

            <catch event="noinput nomatch" count="1">
                Please say the city that your are living at. For example, chicago, los angeles or new york city
                <reprompt/>
            </catch>

            <catch event="noinput nomatch" count="2">
                Apparently the provided city is not in our system. Lets try something different.
                <goto nextitem="countryState" />
                <disconnect/>
            </catch>

            <filled>
                <if cond="offset == '-8'">
                    <prompt>You are living in UTC offset of <value expr="offset"/></prompt>

                    <elseif cond="offset == '-7'"/>
                    <prompt>You are living in UTC offset of <value expr="offset"/></prompt>

                    <elseif cond="offset == '-6'"/>
                    <prompt>You are living in UTC offset of <value expr="offset"/></prompt> 

                    <elseif cond="offset == '-5'"/>
                    <prompt>You are living in UTC offset of <value expr="offset"/></prompt>

                    <elseif cond="offset == '-3.5'"/>
                    <prompt>You are living in UTC offset of <value expr="offset"/></prompt>
                </if>
            </filled>
        </field>

        <field name="formatTime">
            <prompt>
                Twelve hour or twenty four hour clock?
            </prompt>
            <grammar type="application/x-nuance-gsl">
                [[twelve (twenty four)] ?hour]
            </grammar>
        </field>

        <script>
            <![CDATA[
            var d = new Date();
            function calcTime() {
                // create Date object for current location
                var d = new Date();

                // convert to msec
                // subtract local time zone offset
                // get UTC time in msec
                var utc = d.getTime() - (d.getTimezoneOffset() * 60000);

                // create new Date object for different city
                // using supplied offset
                var nd = new Date(utc + (3600000 * (countryState ? countryState : offset)));

                // return time
                if (formatTime == "twelve hour") {
                    return "" + ((nd.getHours() > 12) ? (nd.getHours() - 12) : (nd.getHours()) ) + " and " + nd.getMinutes() + " minutes.";
                } else {
                    return "" + nd.getHours() + " and " + nd.getMinutes() + " minutes";
                }
            }
          ]]> 
        </script>

        <block>
            <prompt>Current time is <value expr="calcTime()" /> </prompt>
            <prompt>Thank you. Bye.</prompt>
            <disconnect/>
        </block>


        <field name="countryState">
            <prompt>
                If you are in U.S., which U.S. state your are currently living in? If you are outside of U.S., which country you are currently living in?
            </prompt>

            <grammar src="map.xml#countryState" type="application/grammar-xml"/>

            <filled>    
                <if cond="countryState == '+8'">
                    <prompt>You are living in UTC offset of <value expr="countryState"/></prompt>

                    <elseif cond="countryState == '+1'"/>
                    <prompt>You are living in UTC offset of <value expr="countryState"/></prompt>

                    <elseif cond="countryState == '+0'"/>
                    <prompt>You are living in UTC offset of <value expr="countryState"/></prompt>

                    <elseif cond="countryState == '-6'"/>
                    <prompt>You are living in UTC offset of <value expr="countryState"/></prompt>
                </if>
                <goto nextitem="formatTime" />
            </filled>
        </field>
    </form>
</vxml>
Node.JS
  • 1,042
  • 6
  • 44
  • 114
  • Which prompts are you experiencing? Only the offset field prompt repeating or do you get the first catch or filled prompts? Do your platform logs provide any detail of what is transpiring? – Jim Rush Dec 07 '15 at 16:53
  • @JimRush The catches work. I hear the first and second catch. Inside the second catch, after saying: "Apparently the provided city is not ... ", it should goto countryState. But it does not and it starts the loop again by saying "What city would you like the time for?" – Node.JS Dec 07 '15 at 20:07
  • 1
    Nothing obvious. Check platform logs. Also, try adding another field or block after the countryState field. If somehow the variable countryState is set, the field might be skipped (the FIA would normally skip if set, but I would expect the goto to override the FIA navigation logic)...wild guess and unlikely to be right, but might help you solve. Its not ignoring because it isn't hitting the disconnect. Its doing something. – Jim Rush Dec 07 '15 at 22:36
  • 1
    @JimRush I was able to solve the issue by wrapping ... with a
    element but I have scope problem now. My question is: How to access elements across forms. For instance, how to access element in a form if I have a form ID. In partitcular, how to access it in java script or scope tag. https://gist.github.com/amir734jj/fc222e5525ca5b30005f
    – Node.JS Dec 10 '15 at 07:25
  • 1
    @Alpha interesting solution. Sounds like a browser bug. In any case, as to your question, create a script block outside of the form(ie page scope). Within the block define your variable. From within any of the other elements you can read or write the value. For larger applications, global data can be defined in a root document. – Jim Rush Dec 10 '15 at 12:39
  • @JimRush You are AWESOME !!! Thank you so much. – Node.JS Dec 10 '15 at 18:14

0 Answers0