How do I escape these characters in the Script Includes for an outbound REST Message

Robin Chadwick1
Giga Expert

ISSUE DESCRIPTION

I have an outbound REST message that sends incident information to the desired endpoint.  The challenge I am having is the following special characters need to be escaped in the Short Description, Description, Comments, and Work Notes.

„ € ‚ … ˆ ‹ ' ' " " • – — ˜ ™ ›

WHAT'S IN PLACE NOW

I'm working with a script includes that populates the REST message and I'm unclear how the replace components are intended to work.

Here are the statements in question:

this.workNotes = this.workNotes.replace(/(\r\n|\n|\r)/gm, " ");  -  What is this replace doing?

this.restMessage.setStringParameter('briefDescription', this.current.short_description.replace(/"/g, "'"));

this.restMessage.setStringParameter('description', this.current.description.replace(/"/g, "'"));

For the last 2 statements, I understand the desired outcome is to replace double quotes with single quotes, but it is not working as desired.

WHAT I NEED

This is outside my area of expertise. 

The content of the description is often a copy and paste from an email.  How do I escape these special characters in the script includes, so that they appear as they are entered in the incident record

„ € ‚ … ˆ ‹ ' ' " " • – — ˜ ™ ›

 

1 ACCEPTED SOLUTION

Pranesh072
Mega Sage
Mega Sage

have you tried setStringParameterNoEscape

View solution in original post

4 REPLIES 4

Pranesh072
Mega Sage
Mega Sage

have you tried setStringParameterNoEscape

Thanks, I have changed the script includes to use setStringParameterNoEscape.

The special characters appear as they are entered in the description.

Willem
Giga Sage
Giga Sage

The replace seems to replace all that match the regular expression /(\r\n|\n|\r)/gm enters and new line symbols. It replaces them with spaces

Have you tried adding the characters to that?
Like so:

this.workNotes.replace(/(\r\n|\n|\r|„|€|‚|…|ˆ|‹|'|'|"|"|•|–|—| |™|›)/g, " ");

 

Example when I use it in background script like this:

var workNotes = "this 'is' an €xample";

workNotes = workNotes.replace(/(\r\n|\n|\r|„|€|‚|…|ˆ|‹|'|'|"|"|•|–|—| |™|›)/g, " ");

gs.print(workNotes)

 

It returns:

*** Script: this  is  an  xample

 

We can use JSON Stringify function

let escapedJson = JSON.stringify(data);