Genesys Cloud - Developer Community!

 View Only

Sign Up

  • 1.  Can an agent script generate a random number?

    Posted yesterday

    Hi all,

    Before I go too far down a rabbit hole, has anyone attempted to generate a random code from within an Agent script?

    A quick search didn't pull back any solid information, that I could find. Our goal here would be to create a button that allows an agent to generate a random 6 digit code (that can then later be sent to a caller via a send SMS data action). 

    Has anyone done something similar within an agent script?

    Thanks in advance!


    #Scripts

    ------------------------------
    Shane Jenkins
    IT Sys Admin Mgr
    ------------------------------


  • 2.  RE: Can an agent script generate a random number?

    Posted yesterday

    Hello, Shane.

    You can use a data action function and consume this in a script. Using NodeJS, you can build a simple or more complex algorithm, if necessary, to generate those numbers. 



    ------------------------------
    Arthur Pereira Reinoldes
    ------------------------------



  • 3.  RE: Can an agent script generate a random number?

    Posted yesterday

    Thanks Arthur! We will definitely explore that.

    We were really hoping for a native ability using dynamic variables or something along those lines would allow for this functionality within the script itself (without stepping out to a data action).

    We also know we can set a random code within Architect and pass into the script, but would like to give an agent the ability to generate a random code dynamically and more than once, if needed. Agent clicks a button, random 6 digit code generated. If agent needs to generate the code again, he/she would click the button again to get another 6 digit code.

    Really appreciate the suggestion! If we pursue that and have success, I'll definitely report back.

    Thanks again!



    ------------------------------
    Shane Jenkins
    IT Sys Admin Mgr
    ------------------------------



  • 4.  RE: Can an agent script generate a random number?

    Posted 15 hours ago

    Hello Shane,

    You can create a dynamic number variable and use random(x,y) for decimal number or randomInt(x,y) for integer number.



    ------------------------------
    Jan Heinonen
    Contact Center Specialist
    GlobalConnect AB
    ------------------------------



  • 5.  RE: Can an agent script generate a random number?

    Posted 7 hours ago

    Thanks Jan! This works excellent. Now for part 2 of my challenge and I'm working on this part currently. Do you know if there is a way to have a button generate the random code and then reset it each time the button is clicked?

    Example, agent clicks the button initially to get a random 6 digit code and then clicks button a second time to get another random 6 digit code. I should be able to use RandomInt(100000,999999) as you mention above to force a random 6 digits. Just not totally sure how to execute or reset it via a button click. (if possible).

    We have executed Data Actions and Open URL's via agent script button clicks, but not set/reset a specific variable like this. Fingers crossed.

    I'll keep testing.

    Thanks again!



    ------------------------------
    Shane Jenkins
    IT Sys Admin Mgr
    ------------------------------



  • 6.  RE: Can an agent script generate a random number?

    Posted 6 hours ago

    This was an interesting one, seems it generates the value of the variable when the script loads so it won't change even if you try to set it again with the a script action. Only way to get a new value is to reload the iFrame.

    I suppose one way to solve it would be to create a bunch of numbers from the start and cycle through them with a script action when you press the button, although it might just be easier to embed a webpage that gives the random numbers.

    Guess this requires some testing, but one idea is to create a string of several codes, and then slice through them when you press a button.
    Or the "ugly" way creating 10 variables and stepping through them when you press a button.



    ------------------------------
    Jan Heinonen
    Contact Center Specialist
    GlobalConnect AB
    ------------------------------



  • 7.  RE: Can an agent script generate a random number?

    Posted an hour ago

    Okey, I got curious as I was sure it could be done so here goes :)

    Create a regular number variable called "index", and one called "randomCode", both with the value 0. (you can change the names if you want to)

    After that create a Custom Script Action with the following. (delay is not needed but it stops the user from double-clicking through numbers)
    The 10 in randomInt[1,10] decides how many codes to create so that can be adjusted if more are needed.

    Add a button to the script and attached the Custom Action to the buttons Click Action setting

    Now when you press the button it will add 1 to index which shows the next code in the list.

    This can of course be finetuned to you requirements with error handling if you go over the numbers of codes etc, but hope this gets you in the right direction :)



    ------------------------------
    Jan Heinonen
    Contact Center Specialist
    GlobalConnect AB
    ------------------------------



  • 8.  RE: Can an agent script generate a random number?

    Posted 5 hours ago
    Edited by Vaun McCarthy 5 hours ago

    This will be useful for something I'd parked a while ago too, thanks.



    ------------------------------
    Vaun McCarthy
    ------------------------------