Genesys Engage on-premises

 View Only

Discussion Thread View
Expand all | Collapse all

Print scxml/vxml statements using Ecma script and loops

  • 1.  Print scxml/vxml statements using Ecma script and loops

    Posted 09-01-2018 04:28
    Hello all.

    Does anyone knows how to create loops inside ecma script to print scxml or vxml ? The idea is to iterate through an array of prompts and play each one of them.

    ------------------------------
    Amauri de Oliveira
    Alctel Telecom
    http://amaurioliveira.com
    ------------------------------


  • 2.  RE: Print scxml/vxml statements using Ecma script and loops
    Best Answer

    GENESYS
    Posted 09-04-2018 12:46
    You can use the <foreach> tag as described in to the ORS SCXML docs here: https://docs.genesys.com/Documentation/OS/8.1.4/Developer/ECMAScript

    ------------------------------
    Jim Crespino
    Director, Developer Enablement
    Genesys
    https://developer.genesys.com
    ------------------------------



  • 3.  RE: Print scxml/vxml statements using Ecma script and loops

    Posted 09-04-2018 13:04
    Hi Jim.

    Thanks for your reply. After some research I found the same that you suggested and it works in parts. In fact you can use the <foreach> in some occasions and it works fine, perhaps I was also interested in changing the attributes inside vxml objects for variables. but it does not work well with the property tags. The only other way that I found to get the job done was writting my own jsp page doing substitutions along the way with java.

    Could you replace properties attributes by ECMA Script variables ? if yes, would you mind sharing ?

    OBS:I noticed that an implicit loop to repeat chunks of code on my xml page will never be possible sue to the fact that ECMA script does not implement DOM completely (guessing).

    ------------------------------
    Amauri de Oliveira
    Alctel Telecom
    http://amaurioliveira.com
    ------------------------------



  • 4.  RE: Print scxml/vxml statements using Ecma script and loops

    Posted 09-04-2018 16:07
    ​1) myAnnc = myArray.shift()    ||    Use an ECMA block to .shift() the first element of the into a script variable and remove it from the array. Alternatively, use .pop() to remove the last element.
    2) Use a Play Treatment block with the script variable that is storing the value from the array (myAnnc) - this value should be the number of the announcement folder, since we are calling for treatment from ORS.
    3) if(myArray.length >=1)  - Use a branching block where the condition evaluates the length of the array, and if the return is greater than 0, you loop back to the ECMA block in step 1, otherwise, you continue processing.

    This loop will continue REMOVING elements of the array until they are exhausted and the .length == 0.

    If you are passing your array variable to the MCP server via attached data, use the same method, but your array will be filled with .wav file names for the MCP server to fetch from a WEB server, instead of announcement folder numbers.

    ------------------------------
    Todd McCall
    Bank of America
    ------------------------------



  • 5.  RE: Print scxml/vxml statements using Ecma script and loops

    Posted 09-04-2018 16:12
    ​If you want to loop in an ECMA block, use the do-while block.
    var text = "";
    var i = 0;
    do {
        text += "The number is " + i;
        i++;
    }
    while (i < 5);


    I like to use the While loop, when the first loop is also conditional:
    var text = "";
    var i = 0;
    while (i < 5) {
        text += "The number is " + i;
        i++;
    }//end while

    ------------------------------
    Todd McCall
    Bank of America
    ------------------------------



  • 6.  RE: Print scxml/vxml statements using Ecma script and loops

    Posted 09-04-2018 19:25
    Is there any reason you can't use a standard loop + prompt blocks available in composer?

    ------------------------------
    Jason Mclennan
    Commonwealth Bank of Australia
    ------------------------------



  • 7.  RE: Print scxml/vxml statements using Ecma script and loops

    Posted 09-05-2018 05:16
    Edited by Amauri de Oliveira 09-05-2018 05:17
    It works partially with the <foreach>.
    Partially because I can only use the ecma script variables in certain types of tags. For example, the ones in green below are working fine, perhaps mcp does not allow me to do the same on the ones in red (Unlesss I´m doing something wrong).

    <script>
    var parameters = {};
    parameters.prompts = ["1.vox","2.vox"];
    parameters.inputmodes = "dtmf";
    parameters.bargein = "true";
    parameters.minlength = "1";
    parameters.maxlength = "5";
            var interdigittimeout = "3s";

    </script>

    <property name="inputmodes" value="parameters.inputmodes" />
    <property name="bargein" value="parameters.bargein" /> <

    block name="Input1P0">

    <prompt gvp:langexpr="AppState.APP_LANGUAGE"> 
    <foreach array="parameters.prompts" item="itemCollection">
    <audio expr="'../Documentos/prompts/' + itemCollection"></audio>
    </foreach>   
    </prompt>

    .....
    .....
    .....

    Thanks ina advance for your help.

    ------------------------------
    Amauri de Oliveira
    Alctel Telecom
    http://amaurioliveira.com
    ------------------------------



  • 8.  RE: Print scxml/vxml statements using Ecma script and loops

    Posted 09-05-2018 08:33
    ​Prepend "AppState." to the beginning of your variable names.

    ------------------------------
    Todd McCall
    Bank of America
    ------------------------------



  • 9.  RE: Print scxml/vxml statements using Ecma script and loops

    Posted 09-05-2018 11:04
    ​er..... what I MEANT to say was... use script variables instead of declaring them within a script block - and THEN you would have AppState.[myVar].
    yeah, that's it.

    ------------------------------
    Todd McCall
    Bank of America
    ------------------------------



  • 10.  RE: Print scxml/vxml statements using Ecma script and loops

    Posted 09-06-2018 06:43
    Hi Todd.

    Thanks for the suggestion. I didn´t have time to try iit yet as I´m busy with another "code" now, perhaps I will give it a go and let you guys know ASAP.

    Cheers

    ------------------------------
    Amauri de Oliveira
    Alctel Telecom
    http://amaurioliveira.com
    ------------------------------



Need Help finding something?

Check out the Genesys Knowledge Network - your all-in-one access point for Genesys resources