sseelam | 2021-11-30 20:51:53 UTC | #1
Hi,
I would like to know the function/syntax, how to search Array data with specific value and return the status?
input request would be a phone number to API and below would be sample response from API however, requirement is to check if ContactModes contains "AUTO_DIAL" in value return successTemplate with true if not false.
Output Response: { "ABC": { "phones": [ { "number": "1234567890", "contactModes": [ "AUTODIAL", "AUTOTEXT", "NODIAL", "MANUALDIAL" ] } ] } }
I have created below response structure and it's returning first value from array however, there could be a possibility values might be out of order so, I am looking specifically to search for "AUTO_DIAL" in response and then return either true/false
{ "translationMap": { "autoDialStatus": "", "pDefault": "", "autoDialCheck": "$.ABC.phones[*].contactModes" }, "translationMapDefaults": { "pDefault": "\"\"", "autoDialStatus": "" }, "successTemplate": "{\"autoDialStatus\": ${successTemplateUtils.firstFromArray(${autoDialCheck})}}" }
Thank you, Sairaj S
Jason_Mathison | 2021-12-06 17:42:28 UTC | #2
Hi Sairaj S,
Here is a working example based on the example that you provided. If more than one phone number may be returned this will require more tweaking.
{ "translationMap": { "ContactMode" : "ABC.phones[0].contactModes[?(@=='AUTODIAL')]" }, "translationMapDefaults": {}, "successTemplate": "{\"test\": \"#if(${successTemplateUtils.firstFromArray(${ContactMode})} == \"${esc.q}AUTODIAL${esc.q}\")true#{else}false#{end}\"}" }
Note that the translation map looks specifically for a contactMode of AUTO_DIAL, and the true/false is handled by the velocity code inside of the successTemplate.
--Jason
sseelam | 2021-12-01 07:36:45 UTC | #3
Thanks for the response. however, I am getting false has return response even for valid value of "AUTO_DIAL".
- Execute:
{ "ABC": { "phones": [ { "contactModes": [ "AUTO_DIAL" ] } ] } }
- Resolve translation map
{ "ContactMode": "[ \"AUTODIAL\" ]", "rawResult": "{\n \"phones\" : [ {\n \"contactModes\" : [ \"AUTODIAL\" ]\n } ]\n }" }
- Apply Output Transformation
{ "test": "false" }
Can you please help.
also, do you have any example to check nested condition's like if contactModes is null, check other kvp attribute value and set either true/false?
Thank you, Sairaj S
Jason_Mathison | 2021-12-10 16:55:33 UTC | #4
Please post the response you are getting (with anything sensitive redacted) and an export of your data action (also with anything sensitive redacted) and what you want / expect to happen.
Another option is to open up a case with support so that you don't have to worry about posting things to a public forum, as well as having a person dedicated to working on this with you.
--Jason
system | 2022-01-10 16:55:39 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: 12802