- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2023 11:44 PM
r.setStringParameterNoEscape('comments', current.comments.getJournalEntry(1));
while sending the comments inthe above REST API form , i am geeting the below error
Please let me know how to send the work notes or comment in REST calls
error:
responsebody {"error":{"message":"Exception while reading request","detail":"The payload is not valid JSON."},"status":"failure"}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2023 01:36 AM
use this and do this for all the values
function jsonEncode(str) {
str = str.replace(/\n/g, "\\n").replace(/\r/g, "\\r");
return str;
}
var comments = current.comments.getJournalEntry(1);
// use this to remove the timestamp and user details and just get the value/text part
var dateRE = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.*\n/;
comments = comments.replace(dateRE, '');
r.setStringParameterNoEscape('comments', jsonEncode(comments));
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2023 01:36 AM
use this and do this for all the values
function jsonEncode(str) {
str = str.replace(/\n/g, "\\n").replace(/\r/g, "\\r");
return str;
}
var comments = current.comments.getJournalEntry(1);
// use this to remove the timestamp and user details and just get the value/text part
var dateRE = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.*\n/;
comments = comments.replace(dateRE, '');
r.setStringParameterNoEscape('comments', jsonEncode(comments));
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2023 01:54 AM
Thanks you Ankur