Legacy Dev Forum Posts

 View Only

Sign Up

Is a DateDiff between two variables possible in an agent script?

  • 1.  Is a DateDiff between two variables possible in an agent script?

    Posted 06-05-2025 19:16

    Shane_Jenkins1 | 2024-09-23 15:41:58 UTC | #1

    Hello all,

    Has anyone attempted a date diff in an agent script?

    We are passing a date/time variable from architect into a screen pop/script and then setting the answer date/time in a script. Both of those seem to be working. What we hope to then do is a datediff between those two date/times variables to get a time difference in ms or seconds.

    Has anyone tried something like this?

    Thanks, Shane


    zubair | 2024-09-23 21:16:30 UTC | #2

    Hi Shane

    I haven't tested myself but I believe its possible using the dynamic variables. You will need to first convert Dates to Milliseconds using dateToMilliseconds then find the difference and lastly convert to readable format using formatDuration

    Hope this helps Zubair


    Shane_Jenkins1 | 2024-09-26 01:10:49 UTC | #3

    Thank you Zubair, this indeed seems to be working. REALLY appreciate the assist.

    A follow-up that you or someone else may be able to assist with. I'm now simply trying to call a data action from within the script to set a custom attribute so that it can be stored as a Custom Attribute, I continue to get an 'unknown error occurred' when trying it. I've tried calling the data action from a button, on page load, etc and all fail with the dreaded unknown error.

    In testing this Genesys Cloud set custom attribute action from Actions, it works perfectly fine.

    Do you or anyone else have experience setting a custom attribute via data action from an agent script?

    We are passing in {{Scripter.Interaction ID}} and {{Scripter.Customer Participant ID}} along with a string text for the attributeValue.

    We are using the following in the Data Action configuration:

    Request: Patch Request URL Template: /api/v2/conversations/${input.conversationId}/participants/${input.participantId}/attributes Request Body Template: {"attributes": {"AnsweredTime": "${input.attributeValue}"}}

    Adding this detail as well, our JSON Response is configured as such: (was thinking maybe it has something to do w the Response).

    { "translationMap": {}, "translationMapDefaults": {}, "successTemplate": "${rawResult}" }

    Thanks again, Shane


    zubair | 2024-09-27 05:57:04 UTC | #4

    Not a problem, Shane.

    There are two things I can think of around patch attribute failure via script.

    1. If you haven't already try passing the string with quotes i.e. "String"
    2. Check the Data Action Integration (oAuth) permissions

    I hope this helps

    Zubair


    system | 2024-10-28 05:57:16 UTC | #5

    This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.


    This post was migrated from the old Developer Forum.

    ref: 29477