How to change to JSON stringify : Cannot decode: java.io.StringReader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2019 06:47 AM
I have this Business Rule for Rest Message Patch method that I need to fix because I keep having this error.
HTTP Status : {"error":{"detail":"Cannot decode: java.io.StringReader@70dd85","message":"Exception while reading request"},"status":"failure"}
(function executeRule(current, previous /*null when async*/) {
// Condition is : current.correlation_idISNOTEMPTY
gs.log('In Business Rule New Run', 'check');
try {
var comment = current.comments.getJournalEntry(1);
gs.log('Comment : ' + comment, 'check');
gs.log('Cor ID : ' + current.correlation_id, 'check');
var r = new sn_ws.RESTMessageV2('Ebond', 'Patch Ebond');
r.setStringParameterNoEscape('sys_id', current.correlation_id);
r.setStringParameterNoEscape('comments',comment);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.log('HTTP Status : ' + responseBody,'check');
}
catch(ex) {
var message = ex.message;
}
gs.log("End Business Rule", 'check');
})(current, previous);
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2019 06:52 AM
That error message could be coming as a response from the API. May be an error occurred on the API side.
Can you test with Postman?
Vinod Kumar Kachineni
Community Rising Star 2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2019 07:32 AM
how to do that? this is my first attempt in using rest. thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2019 10:04 AM
Hi,
Can you check what request body is being sent out?
Have you defined the variable substitutions properly?
gs.info('Request Body is: ' + r.getRequestBody());
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2019 08:30 AM
Hello,
That error is coming from your catch statement here:
catch(ex) {
var message = ex.message;
}
I have found that simply using the following will work and will capture any errors when attempting to execute REST calls:
catch(ex) {
var message = ex;
gs.error('Unexpected error while executing REST message' + ex);
}
Also make sure that you have the correct REST parameter variables (sys_id & comments) defined like so:
See the following for more information on REST variable substitution: Variable substitution in outbound REST messages
Hope this helps.
--David