Genesys Cloud - Developer Community!

 View Only

Sign Up

  • 1.  Velocity Macros and Functions for Translation Map/Success Template

    Posted 05-05-2025 03:14

    Hello Developer Community,

    After reading some previous posts I learned usage of stats.count ; size() ; $.concat
     
    which document helpful to learn different functions we can use similar to size() ?
     
    when I referred "Methods of the List Interface" from https://www.geeksforgeeks.org/list-interface-java-examples/ 
     
    only size() worked, get(int index) or others returning error when used in Translation map. Below are article links, which I am referring
     
    {
    "translationMap": {
    "oActiveUserCount": "$.results[0].data[?(@.metric=='oActiveUsers')].stats.count
     
    }
     
    {
      "translationMap": {
        "OnIdleAgentCount": ".entities.size()"
      },
     
    $.concat($.records[0].Name," - ",$.records[0].Account.Name)
     
    https://developer.genesys.cloud/forum/t/data-actions-convert-string-to-integer-in-sucesstemplate/12188
     
    https://developer.genesys.cloud/forum/t/incorrect-result-from-size-function-in-translation-map/14370
    Thank you!

    #DataActions

    ------------------------------
    Hanumantha Rao
    ------------------------------


  • 2.  RE: Velocity Macros and Functions for Translation Map/Success Template

    Posted 05-06-2025 17:11

    Comparing what you have with something I've written, it looks like your issue in the stats.count example is that you are selecting a single record by index (0) then trying to count it. Try changing "[0]" to "[*]" and see if that makes a difference? In other words:

    {
      "translationMap": {
        "oActiveUserCount": "$.results[*].data[?(@.metric=='oActiveUsers')].stats.count
      }
    }

    For the concat example, the documentation suggests that the concat function takes a single argument, which suggests that you might try this:

    $.records[0].Name.concat(" - ").concat($.records[0].Account.Name)

    (Of course this begs the question whether it is even possible to concatenate an array of values? But in your example it looks like you don't actually need to do that?)

    Hope these ideas help?

    Nick.



    ------------------------------
    Nick Tait
    Genesys Consultant
    ------------------------------



  • 3.  RE: Velocity Macros and Functions for Translation Map/Success Template

    Posted 05-07-2025 00:20

    Hi @Nick Tait Thanks for your answer. I am actually looking which document is helpful to learn different functions we can try similar to size () in above example. 

    Thank you !



    ------------------------------
    Hanumantha Rao
    ------------------------------



  • 4.  RE: Velocity Macros and Functions for Translation Map/Success Template

    Posted 05-07-2025 14:54

    When you are working on a "template" like the "Request URL Template" or "successTemplate" you use Velocity syntax, which includes the Java String capabilities.  For the translation map you can only use JSONPath syntax.



    ------------------------------
    --Jason
    ------------------------------



  • 5.  RE: Velocity Macros and Functions for Translation Map/Success Template

    Posted 05-07-2025 16:39

    Elaborating on what Jason said, these are the resources that I have found most useful:

    • https://help.mypurecloud.com/articles/response-configuration-data-actions/
    • https://help.mypurecloud.com/articles/velocity-macros-data-actions/


    ------------------------------
    Nick Tait
    Genesys Consultant
    ------------------------------



  • 6.  RE: Velocity Macros and Functions for Translation Map/Success Template

    Posted 05-08-2025 11:08

    I also make a lot of use of https://velocity.apache.org/engine/1.7/user-guide.html



    ------------------------------
    George Ganahl GCCX-AI, GCP, GCSME, ICCE, ICHD, etc.
    Technical Adoption Champion
    Genesys
    ------------------------------



  • 7.  RE: Velocity Macros and Functions for Translation Map/Success Template

    Posted 05-09-2025 01:38
    Edited by Hanumantha Rao 05-09-2025 01:38

    Hi @George Ganahl @Jason Mathison  Thanks for your response. 

    from the same page Apache Velocity Engine - User Guide I can use size() method and it returns Integer or array of Integer the way we use.

    example  $.participants.size() or $.participants[*].size() ; discussed the same here Getting no data for translatemap variable - Data Actions - Genesys Cloud Developer Forum ;

    so I understand how to use size() method in my Translation map. as I can see get(2) from below picture (from Apache Velocity page) and try to use isEmpty or get(index) -- I will get error in Translation Map stating function doesn't exist. 

    "Resolve translation map: Failed while processing the translation map. Could not resolve value for the key: 'abc' and no default value was configured. Additional details: Function with name: get does not exist." 

    Assume I am not configuring the output contracts properly, error text clearly indicating it. take an example of JSON result from API output /api/v2/conversations/emails/${input.conversationId} 

    Thank you !



    ------------------------------
    Hanumantha Rao
    ------------------------------



  • 8.  RE: Velocity Macros and Functions for Translation Map/Success Template

    Posted 05-09-2025 08:58

    The translationMap does not support Velocity, it only supports JSONPath.  Both Velocity and JSONPath have size() methods, which is making this confusing.

    I typically use https://www.javainuse.com/jsonpath when I am creating a templateMap. This is not a Genesys site, so I definitely wouldn't post any customer data to it.



    ------------------------------
    --Jason
    ------------------------------