- 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 12:03 AM
when you use this current.comments.getJournalEntry(1) it gives you timestamp and user detail as well
try this once
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', 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 12:07 AM
its removing the time stamp , but my comments are not going to another system. still the same error, check the screenshot
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2023 12:36 AM
can you try to hard-code the comments ?
if it still doesn't work check with the 3rd party team and inform them about the same
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:16 AM
i found the issue but dont know the solution , same issue for description fields as well.
if i am sending the data into second line or multiple lines i am getting this error. with single line data no issues.
responsebody {"error":{"message":"Exception while reading request","detail":"The payload is not valid JSON."},"status":"failure"}
with 400 http response code
below is the body: