ResponseBody blank

kchorny
Tera Guru

I am building an integration between instance1 and instance2. When instance2 posts to the web service on instance1, the incident gets created correctly but I get no response body so I'm unable to pull the remote number out and set it on the initiating incident.

find_real_file.png

When I use REST API Explorer on instance1 and post to the same web service, I get the appropriate response body.

Here is my code:

var request = new sn_ws.RESTMessageV2("ABC Outbound Incident","create_incident");
request.setStringParameterNoEscape("summary",current.short_description);
request.setStringParameterNoEscape("description",jsonEncode(description + ''));
request.setStringParameterNoEscape("number",current.number);
request.setStringParameterNoEscape("company","XYZ");
request.setStringParameterNoEscape("caller","XYZHelp Desk");
request.setStringParameterNoEscape("reported_by","XYZ Help Desk");
request.setStringParameterNoEscape("urgency",urgency);
request.setStringParameterNoEscape("impact",impact);
request.setStringParameterNoEscape("group","Service Desk");
request.setStringParameterNoEscape("sysID",current.sys_id);
request.setStringParameterNoEscape("state","Queued");
request.setStringParameterNoEscape("substate","New");
request.setStringParameterNoEscape("comments",jsonEncode(comments + ''));
var response = request.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.addInfoMessage('httpStatus: ' + httpStatus);
gs.addInfoMessage('responseBody: ' + responseBody);

 

What is going on?

1 ACCEPTED SOLUTION

kchorny
Tera Guru

For anyone who stumbles on this post in the future, I fixed this by giving the user on instance1, whose credentials instance 2 was using to send data to instance1, the import_transformer role to get a response back.

View solution in original post

9 REPLIES 9

Weston Wilson
Tera Expert

What is "ABC Outbound Incident" outbound rest message? 

Yes.

Prateek kumar
Mega Sage

Have you tried JSON parse instead of JSON encode??

https://developer.servicenow.com/app.do#!/api_doc?v=madrid&id=r_JSON-parse_S


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

My issue isn't with sending the request, my issue is getting the expected response body.  All I'm doing here is calling this script:

function jsonEncode(str)
{
str = new JSON().encode(str);
return str.substring(1,str.length - 1);
}

If I don't do that, the target instance will not accept my request.