How to solve : "Bad control character in string literal in JSON" ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi All,
I am trying to pass rejection comments through JSON once the RITM state is rejected.
The JSON payload is :
But I am getting the below error in the response body:
How can I solve this issue?
Thanks in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
another way is to get only the text from the comments by querying sys_journal_field table
(function execute(inputs, outputs) {
// ... code ...
var ritmNo = inputs.ritm_no.sys_id;
var stateValue = inputs.state;
var grApproval = new GlideRecord('sysapproval_approver');
grApproval.addQuery('document_id', ritmNo);
grApproval.addQuery('state', stateValue); // Filter for rejected approvals
grApproval.orderByDesc('sys_created_on'); // Get the most recent rejection
grApproval.query();
var rejectionComments = '';
if (grApproval.next()) {
var rec = new GlideRecord('sys_journal_field');
rec.orderByDesc('sys_created_on');
rec.addQuery('name', 'sysapproval_approver');
rec.addQuery('element', 'comments');
rec.addQuery('element_id', grApproval.sys_id);
rec.setLimit(1);
rec.query();
if (rec.next()) {
rejectionComments = rec.getValue('value');
}
}
// Output the rejection comments for use in subsequent flow steps
outputs.comment = rejectionComments;
})(inputs, outputs);
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hope you are doing good.
Did my reply answer your question?
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Ankur Bawiskar ,
After using JSON.stringify(rejectionComments) it worked. Also, while passing comment through Request body, I have removed the "".
It is working now.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
JSON.stringify you were already using and it didn't work
You can use either of the 2 approaches I shared
1) use directly as below
outputs.comment = rejectionComments;
OR
2) query sys_journal_field and get the value
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
