translationMapDefaults not populating missing attributes

Hi team,

I have an internal data action to get participant data from interactions that we use from Scripter to collect customer data used in scripts and openUrl actions and things.

I have a case where I'm attempting to return a small library of data from the GET /api/v2/conversations/calls/${input.conversationId} endpoint and some of the attributes I am expecting are not present. This is a valid use case, as the library of participant data will depend on the path the customer took through the Architect flow, or whether or not they were found in customer ID API calls etc..

My problem is that the missing attributes are not being populated by my translationMapDefault values. This is causing an error when the Data Action attempts to apply the output translation, as some attributes don't have values.

Here is my translation Map that picks up the customer attributes:
{
"AttributeA": "$.participants[?(@.purpose =="customer")].attributes.AttributeA",
"AttributeB": "$.participants[?(@.purpose == "customer")].attributes.AttributeB",
"AttributeC": "$.participants[?(@.purpose == "customer")].attributes.AttributeC",
"AttributeD": "$.participants[?(@.purpose == "customer")].attributes.AttributeD",
"AttributeE": "$.participants[?(@.purpose == "customer")].attributes.AttributeE",
"AttributeF": "$.participants[?(@.purpose == "customer")].attributes.AttributeF",
"AttributeG": "$.participants[?(@.purpose == "customer")].attributes.AttributeG"
}

Here is my translationMapDefaults that I expect to fill the gaps:
{
"AttributeA": "["Billing1", "Billing2"]",
"AttributeB": "["Peter", "Piper"]",
"AttributeC": "["Peanuts", "Potatoes"]",
"AttributeD": "["0000000000", "1111111111"]",
"AttributeE": "["false", "true"]",
"AttributeF": "["false", "true"]",
"AttributeG": "["0000", "1111"]"
}

Here's what is inside the customer participant returned from the api (no AttributeC, AttributeE or AttributeG value):
"attributes": {
"AttributeA": "Billing2",
"AttributeB": "7184436708",
"AttributeD": "1481975438",
"Result": "0",
"AttributeF": "true",
"CustomerIdDebug": "Failed with search term: tel:+61XXXXXXXXX",
"DebugStep": "Customer ID By Account Success"
}

Here's the resolved translation map:
{
"AttributeA": "[ "Billing2" ]",
"AttributeB": "[ "7184436708" ]",
"AttributeC": "[ ]",
"AttributeD": "[ "1481975438" ]",
"AttributeE": "[ ]",
"AttributeF": "[ "true" ]",
"rawResult":
"AttributeG": "[ ]"
}

And here's the error I'm getting:
{
"message": "Transform failed to process result using 'successTemplate' template due to error:'Unexpected character (',' (code 44)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false')\n at [Source: (String)"{\n "AttributeA": "Billing2", "AttributeB": "7184436708", "AttributeC": , "AttributeD": "1481975438", "AttributeE": "true", "AttributeF": , "AttributeG": }"; line: 2, column: 67]'\n Template:'{\n "AttributeA": ${successTemplateUtils.firstFromArray(${AttributeA})}, "AttributeB": ${successTemplateUtils.firstFromArray(${AttributeB})}, "AttributeC": ${successTemplateUtils.firstFromArray(${AttributeC})}, "AttributeD": ${successTemplateUtils.firstFromArray(${AttributeD})}, "AttributeE": ${successTemplateUtils.firstFromArray(${AttributeE})}, "AttributeF": ${successTemplateUtils.firstFromArray(${AttributeF})}, "AttributeG": ${successTemplateUtils.firstFromArray(${AttributeG})}}'.",
"code": "bad.request",
"status": 400,
"messageParams": {},
"contextId": "f7f30dc9-4861-461d-b58e-2005fb48bc94",
"details": [
{
"errorCode": "ACTION.PROCESSING"
}
],
"errors": []
}

Anyone have any idea why aren't my defaults being used in this case?

Cheers,
Andy

Hello,

It is because of JSONPath - from what I understand - what it considers as error or as empty result.
I mean that with $.partiXYZcipants[?(@.purpose =="customer")].attributes.AttributeA, that would be an error causing the translationMapDefaults to be used.
I think that with something like $.participants[?(@.purpose =="custoXYZmer")].attributes.AttributeA or $.participants[?(@.purpose =="customer")].attribuXYZtes.AttributeA or $.participants[?(@.purpose =="customer")].attributes.AttributeXYZ, it would consider it return an empty result (empty array in this case).

To manage default values for such results (empty array), I leverage the successTemplateUtils.firstFromArray macro with a default value used when array is empty.
E.g.
"successTemplate": "{\n \"result\": ${successTemplateUtils.firstFromArray(\"${AttributeA}\",\"${esc.quote}UNKNOWN${esc.quote}\")}\n}"
In case of empty array, this will return 'UNKNOWN'.

Regards,

Thanks Jerome, that is working for me. I'll definitely tuck this one away to use again in the future!

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