Escape characters within JSON object not working, even when converted to a string

Logan3
Kilo Explorer

Hello,

Using Flow Designer, I'm trying to update the work notes field of an Alert with the response body from a REST step. This is fine, but the resulting work note ignores escape characters, specifically "\n".

Is there a reason this could be happening, and is there a workaround to get escape characters to work?

I have tried manually converting the JSON object to a string using .stringify(), but the same issue remains. I've tried escaping the escape with "\\n". The same issue is occurring when updating an Alert manually through a glide record object.

Thank you.

6 REPLIES 6

Hi Ashutosh,

Thanks for the response.

<br/> and other escape characters are not working as well.

VaranAwesomenow
Mega Sage

If you construct JSON in a script then ServiceNow automatically escapes special characters

 

for example

If you want to create an incident JSON below code should escape any characters that would break JSON in short description for example if short description is technology issue" ..}

 

output would look like this

 

*** Script: [DEBUG] technology issue" ..}
*** Script: [DEBUG] object
*** Script: [DEBUG] {"number":"INC0010004","shortDesc":"technology issue\" ..}"}
[0:00:00.005] Total Time
var incJSON = {};
var grInc = new GlideRecord('incident');
grInc.get('f6e105891b7f101036f521b9bc4bcba9');
gs.debug (grInc.short_description);
incJSON.number = grInc.number + '';
incJSON.shortDesc = grInc.short_description + '';
gs.debug(typeof incJSON);
var incJSONString = '';
var test = JSON.stringify(incJSON);
gs.debug(test,'anil' );