Nathan_Tossens | 2019-07-26 06:50:46 UTC | #1
Dear community,
currently working on a data action to search through the external contact given a phone number.
In my response, I need to get the firstName of the external contact and also his title.
This is working fine, but my problem is that I need to configure the response so that the Title is limited in size. Is there a way to do this?
Here is my response configuration :
{ "translationMap": { "title": "$.entities[0].title", "firstName": "$.entities[0].lastName" }, "translationMapDefaults": { "title": "\"\"", "firstName": "\"\"" }, "successTemplate": "{\n \"entities.title\": ${title}\n,\n \"entities.firstName\": ${firstName}\n}" }
What I would like is to do something in the succesTemplate to specify that ${title} cannot be greater than 20 char for instance.
Thanks for your help.
Kind regards,
Tossens Nathan
Jason_Mathison | 2019-07-26 14:20:47 UTC | #2
Hi Tossens,
Our documentation for Velocity macros inside of templates includes information on being able to use java string manipulation methods:
https://help.mypurecloud.com/articles/velocity-macros-data-actions/#JavaStringMethods
This will lead you to the Java string library: https://docs.oracle.com/javase/7/docs/api/index.html?java/lang/String.html
You are probably going to want to use the substring method.
--Jason
Jason_Mathison | 2019-07-26 14:48:16 UTC | #3
A couple of other options that might be easier: In Architect there is a Substring() method to chop the title down to size. Scripts has a similar method substr().
anon28066628 | 2019-07-29 14:31:31 UTC | #4
Hi Nathan, please see the Velocity macros supported for successTemplates here:
https://help.mypurecloud.com/articles/velocity-macros-data-actions/#JavaStringMethods
The Java substring method should get what you need.
Nathan_Tossens | 2019-08-06 06:29:35 UTC | #5
Dears,
thanks a lot for your answer. I can't do it in architect due to the implementation so I need to do it in the Data Action, response configuration.
I was also looking at the Velocity Maccro to do this but I was not able to find an example with the Java string library.
How would you do it in the Response Configuration :
{ "translationMap": { "title": ".entities[0].title", "firstName": ".entities[0].lastName" }, "translationMapDefaults": { "title": """", "firstName": """" }, "successTemplate": "{\n "entities.title": {title}\n,\n \"entities.firstName\": {firstName}\n}" }
I would need the title limited to 20 char. How would you implement it there?
Kind regards.
Nathan_Tossens | 2019-08-06 08:17:37 UTC | #6
Ok,
I found how to do this.
For people who may want to know here is my solution :
"successTemplate": "{\n \"entities.title\": ${title.substring(0,14)}\"\n,\n \"entities.firstName\": ${firstName}\n}"
Kind regards and thanks for help :)
system | 2019-09-06 08:17:40 UTC | #7
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: 5641