AppFoundry: The Genesys Marketplace Experience

 View Only

Sign Up

Expand all | Collapse all

Disabling a button in script outside of certain hours

  • 1.  Disabling a button in script outside of certain hours

    Posted 5 hours ago

    I would like to be able to diable a button in scripting oyt side of teh hours 5pm to 9am, i have a data action setup to get the current time that works well, but the variable and actions dont appear to work how i have been reading, any help would be great



    ------------------------------
    Simon Oldroyd
    ------------------------------


  • 2.  RE: Disabling a button in script outside of certain hours

    Posted 5 hours ago
    Edited by Phaneendra Avatapalli 5 hours ago

    Hi Simon,

    In the button's Visible property, you should be able to use a true/false expression based on a script variable.

    For example, if your data action returns a boolean like isAfterHours, map that to a script variable such as Script.IsAfterHours.

    Then in the button Visible expression, you could use something like:

    !Script.IsAfterHours

    That way:

    • During 5pm–9am, IsAfterHours = true, so the button is hidden

    • During 9am–5pm, IsAfterHours = false, so the button is visible

    My understanding is the data action would need to run when the interaction/script loads, because the script won't continuously re-check the time unless something triggers the action again.

    For new interactions after 5pm this should work fine, as the script will load and evaluate the current time then. The only edge case would be an interaction already open before 5pm, unless the check is triggered again.

    Hope this helps.
    ------------------------------
    Phaneendra
    Technical Solutions Consultant
    ------------------------------



  • 3.  RE: Disabling a button in script outside of certain hours

    Posted 4 hours ago

    Thanks for the response but i think it is the script variable that i am actually struggling with



    ------------------------------
    Simon Oldroyd
    ------------------------------



  • 4.  RE: Disabling a button in script outside of certain hours

    Posted 4 hours ago

    Hi Simon, No worries what are you currently getting back from the time check data action?

    For example:

    • Is it returning the raw current time?

    • Or are you already returning a true/false value such as isAfterHours?

    Also, are you able to successfully map the data action output into a script variable, or is that the part that is failing?

    I think understanding what the action response/output looks like will help narrow down whether the issue is with:

    • the data action response,

    • the script variable mapping,

    • or the button Visible expression itself.



    ------------------------------
    Phaneendra
    Technical Solutions Consultant
    ------------------------------



  • 5.  RE: Disabling a button in script outside of certain hours

    Posted 4 hours ago

    raw curret time currently, in the script last week i added the variable with the time for in and out of hours but teh variable to get current time didnt work returnign Nan, so i have removed it all to start again



    ------------------------------
    Simon Oldroyd
    ------------------------------



  • 6.  RE: Disabling a button in script outside of certain hours

    Posted 3 hours ago
    Edited by Phaneendra Avatapalli 3 hours ago

    Hi Simon,

    I did a quick test on this and managed to get the button visibility working using a number variable.

    In the script, I created a number variable called CurrentHour, then used the button's Visible property with a True/False expression.

    The expression I tested was:

    ({{CurrentHour}} >= 9 and {{CurrentHour}} < 17)

    I then passed different values into CurrentHour (as Number) from the screen pop/script input:

    • 10 → button was visible

    • 17 → button was hidden

    So if your data action can return just the current hour as a number, for example 17, then you should be able to map that value into the script input variable and use it in the Visible expression.

    That avoids trying to parse raw time in the script, which may be what was causing the NaN issue.

    Hope this helps.



    ------------------------------
    Phaneendra
    Technical Solutions Consultant
    ------------------------------



  • 7.  RE: Disabling a button in script outside of certain hours

    Posted 2 hours ago

    Also, if your data action can only return raw time, another option is to do the conversion in Architect before the screen pop.

    For example:

    • Data action returns raw current time

    • Architect extracts/converts that into the current hour as a number

    • Pass that number into the script input variable, for example CurrentHour

    • Script uses the Visible expression:

    ({{CurrentHour}} >= 9 and {{CurrentHour}} < 17)

    That way the script still only receives a clean number and does not need to parse the raw time directly.

    Hope this helps.



    ------------------------------
    Phaneendra
    Technical Solutions Consultant
    ------------------------------



  • 8.  RE: Disabling a button in script outside of certain hours

    Posted 2 hours ago

    So i have the button hidden good start thanks for that but i need it to be in GMT+930 time cause currently it appears to be UTC server time which is 3am



    ------------------------------
    Simon Oldroyd
    ------------------------------



  • 9.  RE: Disabling a button in script outside of certain hours

    Posted an hour ago

    Great, sounds like the button visibility part is working now.

    For the timezone issue, I think the easiest approach is to keep the script simple and do the timezone conversion before the value reaches the script.

    In my quick test, I used a number variable called CurrentHour and this button Visible expression:

    ({{CurrentHour}} >= 9 and {{CurrentHour}} < 17)

    That worked as expected:

    • 10 → button visible

    • 17 → button hidden

    So for your setup, I'd suggest having the data action return the local hour for GMT+9:30 as a number in 24-hour format, rather than UTC/server time.

    For example:

    UTC 03:00 → local 12:30 → pass CurrentHour = 12

    Then the same Visible expression should work, and the script does not need to parse raw time or handle timezone conversion.

    The key is that CurrentHour should be the converted local hour in 24-hour format, for example:

    • 9 = 9am

    • 12 = midday

    • 17 = 5pm



    ------------------------------
    Phaneendra
    Technical Solutions Consultant
    ------------------------------



  • 10.  RE: Disabling a button in script outside of certain hours

    Posted an hour ago

    so Currenthour that you use is the name of the data action? the data action i have created is named currentdate /api/v2/date and that works when i run the test on it, but how do i put the offset in the dataaction which i will need to create a new one of course



    ------------------------------
    Simon Oldroyd
    ------------------------------



  • 11.  RE: Disabling a button in script outside of certain hours

    Posted an hour ago

    CurrentHour is just the script variable name I used in my test, not the data action name.

    Your data action can still be called currentdate.

    If /api/v2/date is returning UTC time, I don't think I'd try to make the script handle the offset directly. I'd convert the time before passing the value into the script.

    For GMT+9:30, you need to add 570 minutes to the UTC time:

    • 9 hours × 60 = 540

    • + 30 minutes = 570

    For example, in Architect logic before the screen pop, you could do something like:

    Flow.LocalDateTime = AddMinutes(GetCurrentDateTimeUtc(), 570)

    That would return the full converted local date/time.

    Then you can extract just the local hour using:

    Flow.CurrentHour = Hour(Flow.LocalDateTime)

    Then pass Flow.CurrentHour into the script input variable:

    CurrentHour

    The script button Visible expression can then stay as:

    ({{CurrentHour}} >= 9 and {{CurrentHour}} < 17)

    So the script receives the converted local hour in 24-hour format, rather than UTC/server time.

    Hope this helps. 



    ------------------------------
    Phaneendra
    Technical Solutions Consultant
    ------------------------------



  • 12.  RE: Disabling a button in script outside of certain hours

    Posted an hour ago

    firstly thanks you so much for you continued help.

    So in my incoming call flow there is no such flow localdatetiem, it says i shoudl be able to creat e but once again this is not clear hoiw to add a flow variable



    ------------------------------
    Simon Oldroyd
    ------------------------------



  • 13.  RE: Disabling a button in script outside of certain hours

    Posted 38 minutes ago

    No worries at all.

    Flow.LocalDateTime was just an example variable name it won't already exist in your flow.

    If you are doing this inside a task in an Inbound Call Flow, you can create it as a Task variable instead.

    In the task, add an Update Data action before the screen pop.

    In that Update Data action, add a DateTime variable, for example:

    Task.LocalDateTime

    Set it to:

    AddMinutes(GetCurrentDateTimeUtc(), 570)

    Then add another variable as an Integer/Number, for example:

    Task.CurrentHour

    Set it to:

    Hour(Task.LocalDateTime)

    Then in the screen pop/script input mapping, pass:

    Task.CurrentHour

    into your script variable:

    CurrentHour

    So the flow is:

    UTC time → add 570 minutes → local date/time → extract hour → pass hour into script.



    ------------------------------
    Phaneendra
    Technical Solutions Consultant
    ------------------------------