When I run the JavaScript and VXML codes separately they are working fine. But when I try to call JavaScript function through the VXML code it is not working. Please find the VXML code below. Please help me to solve the issue.
<vxml version="2.1">
<form id="selectSong">
<block>
<script>
<![CDATA[
function selectSong()
{
var number = 1;
var currSong = '../songs/buddhist/0001.wav';
var fields = currSong.split('/');
var song = fields[3];
var fields_song = song.split('.');
var num = fields_song[0];
if (number == 1) {
num++;
} else if (number == 2) {
num--;
}
if (num > 9 && num < 99)
{
return "'../songs/buddhist/00" + num + ".wav'";
} else if (num < 9 && num > 0) {
return "'../songs/buddhist/000" + num + ".wav'";
} else if (num > 99 && num > 999) {
return "'../songs/buddhist/0" + num + ".wav'";
} else {
return "'../songs/buddhist/" + num + ".wav'";
}
}
]]>
</script>
</block>
<block>
<prompt>
<audio expr="'../Prompts/Press1.wav'" />
<audio expr="'../Prompts/SelectLangPreference.wav'" />
</prompt>
</block>
<field name="getNum" >
<grammar xml:lang="en-US" root = "MYRULE" mode="dtmf">
<rule id="MYRULE" scope = "public">
<one-of>
<item> 1 </item>
<item> 2 </item>
<item> 3 </item>
<item> 4 </item>
</one-of>
</rule>
</grammar>
<filled namelist="getNum" mode="all">
<if cond="getNum == 1">
<prompt>
<audio expr="selectSong()" />
</prompt>
</if>
</filled>
</field>
</form>
</vxml>
"block" element makes anonymous scope. Because your variable couldn't reach your "field" element. Perhaps you have two solution.