Legacy Dev Forum Posts

 View Only

Sign Up

Data Action - Translation Maps, Defaults & Success Templates

  • 1.  Data Action - Translation Maps, Defaults & Success Templates

    Posted 06-05-2025 18:43

    Craig_Golby | 2022-10-31 15:07:13 UTC | #1

    Hi there - I am trying to modify a Genesys Data Action Used to retrieve data from Participant Data in Genesys for use in a post call Survey Script.

    Generally, it is working OK, but our Customers Security Check, and can do so either through the IVR or with an Agent, as such our Participant Data can be in either "ivr" or "agent" Attributes Section, sometimes the variables are blank, where an Agent was unable to Security Check the Customer.

    In my Translation Map I have "forenameOpt1": "$.participants[0].attributes.FirstName", "forenameOpt2": "$.participants[?(@.purpose=='agent')].attributes.forename",

    In my Translation Map Defaults, whilst I know the second returns an array, I have "forenameOpt1": "\"Unknown\"", "forenameOpt2": "\"Unknown\"",

    And then within the Success Template, amongst many other fields I have \"forename\": #if(${forenameOpt1} == \"Unknown\") ${successTemplateUtils.firstFromArray(${forenameOpt2})}#{else}${forenameOpt1}#{end},

    It validates and saves fine, when I run this and look at the Resolve Translation Map, I can see "forenameOpt1": "\"Unknown\"", "forenameOpt2": "[ \"Jonathan\" ]",

    But the final result in this scenario is "Unknown"

    It is possible that one or both or neither field will be populated when the DA fires, so I need to cover off all scenarios - I could feed both Opt1 & Opt2 through and manage the decision making in the Survey Flow (we do this elsewhere), however this feels more graceful in that only the necessary bit of data is passed.

    Thoughts anyone ???


    Craig_Golby | 2022-10-31 18:04:28 UTC | #2

    Changing the Success Template section from "forename": #if(${forenameOpt1} == "Unknown") ${successTemplateUtils.firstFromArray(${forenameOpt2})}#{else}${forenameOpt1}#{end}

    to \"forename\": #if($forenameOpt1 == \"${esc.q}Unknown${esc.q}\") ${successTemplateUtils.firstFromArray(${forenameOpt2})}#{else}${forenameOpt1}#{end}"

    Seems to of done the trick - Found by searching the archives for similar problems and glueing a couple together :slight_smile:

    I would however welcome any comments / suggestions


    Jason_Mathison | 2022-11-01 20:12:18 UTC | #3

    Hey Craig,

    Bravo for sorting this out on your own with the help of the archives!

    --Jason


    H.Holloway | 2022-11-24 14:07:06 UTC | #4

    Craig_Golby, post:1, topic:16985
    r

    Is there any material or tutorials on how to create expressions and create templates?


    Jason_Mathison | 2022-11-29 11:07:04 UTC | #5

    I created a video to get people started:

    https://www.youtube.com/watch?v=o4L6qOqWKdY&ab_channel=GenesysCommunity

    Some of our documentation: https://help.mypurecloud.com/articles/velocity-macros-data-actions/

    Here are the 3rd party tools I typically use: https://jsonpath.herokuapp.com/ to work out the JsonPath used in the translationMap. Unlike the next two suggestions which are a matter of taste, this one is pretty important as different JsonPath engines have different behavior.

    mockable.io as the endpoint that my data actions hit while testing. https://jsonlint.com/ to beautify my JSON and find syntax errors.

    https://developer.genesys.cloud/devapps/api-explorer For working with the Genesys Cloud APIs. Postman - For initially working with a 3rd party endpoint. Data Actions are not a great place to learn how to use the API. ngrok - If I need to see what is actually going on between Genesys Cloud and the endpoint.


    H.Holloway | 2022-11-28 19:50:38 UTC | #6

    Thank you, I was actually going to ask you where I could find some material on this via post https://developer.genesys.cloud/forum/t/data-action-response-assistance/17382/7 as I was unsure where you got the idea to use replaceFirst from and I did not find it in the documentation. Looks like there is a lot I need to learn and wanted to find out if you had some tutorials, pointers etc.

    I tried this link https://www.genesys.com/webinars/learn-how-to-setup-and-execute-a-data-action-api-request-before-routing-a-call, however, it states that it has been moved? I am interested in this DevCast very much, is it on the YT channel?

    Thank you for the jsonpath app too, I have been using https://jsonpathfinder.com/ which has been useful and thought I would share it.

    Can't thank you enough, really appreciate this.


    Jason_Mathison | 2022-11-29 12:06:40 UTC | #7

    I updated the video link so it should be working now. For the replaceFirst you can look at the Java 17 "String" documentation to see all of the string functions that are available to you:

    https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/String.html


    system | 2022-12-30 12:07:26 UTC | #8

    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: 16985