Legacy Dev Forum Posts

 View Only

Sign Up

Help with translationMap in my Data-action

  • 1.  Help with translationMap in my Data-action

    Posted 06-05-2025 18:43

    Manvendra_Singh | 2021-11-08 14:04:26 UTC | #1

    Hi all, greetings!

    I'm finding it difficult to achieve few basic things in data-action's translationMap. Please consider the 'translationMap' code below:

    "translationMap": { "code": "$.participants[?(@.purpose == 'agent')].wrapup.code" }

    This will error out when there is no 'participant' with purpose as 'agent', as it results in an empty array followed by 'wrapup.code'. So here, I want to add some sort of 'null check' which makes sure that 'wrapup.code' is only accessed when such a participant is found. Otherwise a default code is sent.

    Secondly, I also want to add a conditional statement in the above translationMap, something like below: "translationMap": { "code": "$.participants[?(@.purpose == 'agent')].wrapup.name ? $.participants[?(@.purpose == 'agent')].wrapup.name : $.participants[?(@.purpose == 'agent')].wrapup.code" }

    But I'm not sure what is the right syntax to achieve these two. If someone can share some idea on this, that would be a great help for me and my team.

    Thanks & Regards Manvendra


    Jerome.Saint-Marc | 2021-11-18 17:52:30 UTC | #2

    Hello,

    I don't think that "code": "$.participants[?(@.purpose == 'agent')].wrapup.code" will error out when there is no participant with purpose agent. The JSONPath expression will also send back an empty array in this case.

    But to answer your question, when there is an error on the JSONPath expression, you can define a default value for code in translationMapDefaults. Based on your translationMap and your JSONPath expression, the code variable is supposed to be an array (of strings). If you want the default value to be an empty array, you would set this:

    "translationMapDefaults": { "code": "[]" }

    If you want the default value to be an array with a specific/default value in it, you would set this:

    "translationMapDefaults": { "code": "[\"default\"]" }

    Regarding your last question, I am not sure such thing exists. It depends a bit what you are trying to get and to manage. If the agent has set a wrapup code, then wrapup.name and wrapup.code will exist with a non-empty value. If the agent has not set a wrapup code (conversation is terminated but the wrapup was optional), you would have wrapup.code containing an empty string and no wrapup.name

    So if you are only interested in retrieving wrapup.name when the wrapup has been set by the agent (and the conversation is terminated), you could use something like this in your JSONPath expression: "nameArray": "$.participants[?(@.purpose == 'agent' && @.wrapup.code != '')].wrapup.name"

    Regards,


    Manvendra_Singh | 2021-11-19 03:43:16 UTC | #3

    Thanks a ton for the update Jerome, this has solved my issue :slight_smile:

    Regards Manvendra


    system | 2021-12-20 03:44:14 UTC | #4

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