Since scripter is a bit limited in what you can really do with strings, can you do things like nested .Replace when calling an input contract variable and have it strip out trailing spaces (but to leave a middle space such as in "John Smith"), carriage returns and tabs?
You have access to fairly powerful string tools, like this one:
--Jason
Hi Jason,
I was trying to remove trailing and leading spaces using this regex expression: "\A\s+|\s+\Z.". I tested it on regex101.com and it returned spaces only at the beginning and at the very end. When I tried to do this in successTemplate using replaceAll, it didn't work. Do you know what I'm doing wrong?
Below is my response configuration:
{
"translationMap": {
"name": "$.entities[*].name",
"content": "$.entities[*].texts[0].content"
},
"translationMapDefaults": {
"name": "\"\"",
"content": "[]"
},
"successTemplate": "{ \"content\" : $content.replaceAll(\"</p>|<br />\",'\\\\n').replaceAll(\"<[^>]+>\",
\"\").replaceAll(\" \", \" \").replaceAll(\"&\", \"&\").replaceAll(\"“\", \"โ\").replaceAll(\"”\",
\"โ\").replaceAll(\"‘\", \"โ\").replaceAll(\"’\", \"โ\").replaceAll(\"–\", \"โ
\").replaceAll(\"— \", \"โ\").replaceAll(\"ñ\", \"รฑ\").replaceAll(\"á\",
\"รก\").replaceAll(\"é\", \"รฉ\").replaceAll(\"\\\\A\\\\s+|\\\\s+\\\\Z\",\"\"), \"name\" : $name }"
}
Hi Artur,
I worked through this issue with a response of:
{
"foo" : " bar "
}
In your example you use \A and \Z which are assertions. It seems to work in the regex101 tester, but I have never tried to use them in a successTemplate. Switching to ^ and $ seems to work. Finally, I had to account for there being a quote at the start and end of the variable, so I replace the double quote followed by whitespace with a double quote.
{
"translationMap": {
"foo": "foo"
},
"translationMapDefaults": {},
"successTemplate": "{ \"foo\" : $foo.replaceAll(\"^$esc.quote\\s+|\\s+$esc.quote$\", \"$esc.quote\")}"
}
--Jason
Thanks Jason, I tried it but for some reason it didn't work for me, I found how to remove space in the beginning using .replaceAll(\"<div[^>]+>\\\\n\",\"\")
and spaces at end in Genesys Script
Is there anything else you need a this point?
Nope, I am good thanks!
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.