replace double quotes with "\ when sending REST message

abhilash5
Tera Contributor

i need to replace double quotes with "\ when sending REST message. but when used below replace method, the final output which user receives in email is coming as "Testing double quotes"

 

first in WF : i am setting sub value and using the below

var sub1 = sub.replace(/"/g, '\\"');
 
Then Rest message is called from SI which then send it to external system. Then external system sends the sub value in the email. where it is sending in the this format 
"Testing double quotes"

please help me, as this issue is occuring when user is entering the subject value in the record with double quotes
8 REPLIES 8

@abhilash5 

that's correct.

It's the fault of external system since you are able to replace it before sending to them.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@abhilash5 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

@abhilash5 

to ensure double quotes are sent as it is, you can use setStringParameterNoEscape(), instead of using 

setStringParameter()

Outbound REST Message Script API - RESTMessageV2().setStringParameter() does not escape accented let... 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Community Alums
Not applicable

Hi @abhilash5 ,

Can you verify the external system is trying to protect against XSS (cross-site scripting) attacks? It may causes to converting special characters.

Possible solution for this requirement is - you can try with following script:

Try to replace the double quotes with a character that is less likely to be encoded into HTML entities

    var sub1 = sub.replace(/"/g, '%%quot%%'); 

and then:

    sub1 = sub1.replace(/%%quot%%/g, '"');