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

Ankur Bawiskar
Tera Patron
Tera Patron

@abhilash5 

what's your business requirement here?

are you facing an issue while sending double quotes in REST Message body?

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

requirement is. servicenow is sending double quote but the external system(esign tool) is not able to process it stating incorrect JSON structure. so they are saying to replace double quotes with "\, so their tool can accept this JSON value and will send the double quotes as it is to user

Basically they are using this value as subject line to send email notification to end user

@abhilash5 

your line of code worked for me.

what's not working in your case?

var str = 'Hello " Adam';

var sub1 = str.replace(/"/g, '\\"');
gs.info(sub1);

AnkurBawiskar_0-1739181074882.png

 

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

Right same for me. what i discovered is, the payload is hitting to external system correctly however while it sends an email to user, it is showing the subject line as : "Testing double quotes"

So i think external system is not able to process it properly. so at the moment it doesn't look an issue at servicenow.