REST webservice response {"error":{"message":"Exception while reading request","detail":"Cannot decode: java.io.StringReader@1bb1c76"},"status":"failure"}

sry
Giga Guru

Hi, i am doing a rest integration with two servicenow instances for incident module and i am getting below error for response when REST service is initiating the call.

{"error":{"message":"Exception while reading request","detail":"Cannot decode: java.io.StringReader@2cc3d83"},"status":"failure"}

i have created outbound REST with HTTP headers "accept = application/JSON" and "content-Type = application/JSON"

and in the script i am passing the description like below (after trial and error i find incident description is creating this issue if we have given multiple lines of text, but its not an issue if i have given only a single line of text)

r.setStringParameterNoEscape('description',current.description);

and in the POST function i am passing content like below

{
"short_description":"${short_description}",
"description":"${description}",
}

i searched community and try to understand the issue but still not able to find accurate help to fix this error. Please help me if anyone has encountered this issue.

Business rule script:

(function executeRule(current, previous /*null when async*/) {
try {

var r = new sn_ws.RESTMessageV2(' REST Incident', 'post');
r.setStringParameterNoEscape('short_description', current.short_description); 
r.setStringParameterNoEscape('description',current.description);
r.setStringParameterNoEscape('callerID',current.sys_id);

var response = r.execute();
var responseBody = response.getBody();
gs.log("rbody is "+responseBody);
var json = responseBody;
var obj = JSON.parse(json); 
var foundsysID = obj.result.sys_id; 
current.correlation_id = foundsysID; 
current.update(); 

var httpStatus = response.getStatusCode();
}
catch(ex) {
var message = ex.message;
}
})(current, previous);

 

thanks,

sry

1 ACCEPTED SOLUTION
4 REPLIES 4

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI,


Try this:

r.setStringParameterNoEscape('short_description', current.getValue('short_description)); 
r.setStringParameterNoEscape('description',current.getValue('description));
r.setStringParameterNoEscape('callerID',current.getValue('sys_id')); I dont see this in content

{
"short_description":"${short_description}",
"description":"${description}",
}

 

Thanks,
Ashutosh

Hi Ashutosh, thank you for prompt reply.

 

i tried current.getValue('field_name') for every field but still same error in the log.

 yes the content was missing caller, i have corrected it.

{
"short_description":"${short_description}",
"description":"${description}",

"correlation_id":"${callerID}",
}

Hi Ashutosh, thank you very much. below article helped for my issue.

https://community.servicenow.com/community?id=community_question&sys_id=160ad2c6db93e700107d5583ca9619c4&anchor=answer_bc15ab06dbd32f409a64e15b8a9619cd&view_source=searchResult

 

thanks,

sry