I am getting a HTTP status 0 while making an rest call from servicenow to servicenow instance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2022 01:21 AM
Hello everyone,
I am using Rest api integration to send attechment frpm one servicenow instance to another sometimes its working fine but sometimes its returning status HTTP status 0 .... Can some please help me wat can be the exact problem, below is my code related to same
var answer = "";
var attachmentMsg = "";
var level = "0";
attachmentMsg = "The business rule is started";
var source = "BusinessRule";
var sycLog = new global.LogEntry();
sycLog.addLogEntry(level, attachmentMsg, source);
var attachmentCount = sendAttachments(current.getTableName(),
current.sys_id, current.ob_id);
if (attachmentCount != "none") {
attachmentMsg = " Attachments successfully sent: " +
sycLog.addLogEntry(level, attachmentMsg, source);
attachmentCount[0].toString() + ". Attachments failed to be sent: " +
attachmentCount[1].toString();
} else {
attachmentMsg = " Record had no attachments to send.";
sycLog.addLogEntry(level, attachmentMsg, source);
}
// else {
// answer = "Incident could not be sent.";
// }
answer = answer + attachmentMsg;
// Set message at top of screen with results.
//gs.addInfoMessage(answer);
function sendAttachments(sourceTable, sourceID, targetID) {
attachmentMsg = " Inside Function";
sycLog.addLogEntry(level, attachmentMsg, source);
attachmentMsg = sourceTable + "_" + sourceID + "_" + targetID;
sycLog.addLogEntry(level, attachmentMsg, source);
var answer = [0, 0]; //successful attachments, failed attachments
// Query for any attachments on the current record.
var tableName = current.ob_table_name;
var attachmentRec = new GlideRecord("sys_attachment");
attachmentRec.addQuery("table_sys_id", sourceID);
attachmentRec.addQuery("table_name", sourceTable);
attachmentRec.addQuery('sys_created_by', '!=', "Sycor.Ottobock.Rest.User");
attachmentRec.addQuery('u_send',"");
attachmentRec.query();
if (attachmentRec.next()) {
attachmentMsg = " Inside Glide Record: " + attachmentRec.file_name + " send value " + attachmentRec.u_send+" "+tableName+" "+targetID+" "+attachmentRec.content_type;
sycLog.addLogEntry(level, attachmentMsg, source);
var attachmentMessage = new sn_ws.RESTMessageV2('Ottobock', 'UpdateAttachments');
attachmentMessage.setQueryParameter("table_name", tableName);
attachmentMessage.setQueryParameter("table_sys_id", targetID);
attachmentMessage.setQueryParameter("file_name", attachmentRec.file_name);
attachmentMessage.setRequestHeader("Content-Type", attachmentRec.content_type);
attachmentMessage.setRequestHeader("Accept", "application/json");
attachmentMessage.setRequestBodyFromAttachment(attachmentRec.sys_id);
var response = attachmentMessage.execute();
response.waitForResponse(60);
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
var newSysID = response.getResponseAttachmentSysid();
attachmentMsg = "Response: " + response + "ResponseBody: " + responseBody + "HttpStatus: " + httpStatus;
sycLog.addLogEntry(level, attachmentMsg, source);
if (httpStatus.toString() == "201") {
answer[0] += 1;
attachmentMsg = "Send Value: " +attachmentRec.u_send;
sycLog.addLogEntry(level, attachmentMsg, source);
attachmentRec.u_send = "Sent";
attachmentRec.update();
} else {
answer[1] += 1;
}
}
// } else {
// answer = "none";
// }
return answer;
}
})(current, previous);
- Labels:
-
Integrations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2022 07:10 AM
Hi Arundhati,
Issues like this are a nuisance to troubleshoot. The first thing I find very off is that you are getting a 0 response code. That would imply that you are not actually sending those messages. As you know, if there is an issue in the other instance, you would get back a code in the 400 or 500 range.
I would suggest that you check the logs on both instances to make sure that your message is actually being sent and if it is perhaps there's an issue on the receiving side such that it is not acknowledging receipt.
Hope that helps.
:{)
Helpful and Correct tags are appreciated and help others to find information faster
:{)
Helpful and Correct tags are appreciated and help others to find information faster
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2022 10:14 AM
Hi John,
We are facing similar kind of issue, may i request you to please look into the below community post, we are unable to find the resolution.
https://community.servicenow.com/community?id=community_question&sys_id=ffbd52e9dbf20510bb4a474d1396197c
Thanks, Jay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2022 06:21 AM
Hi Jay,
I just put a reply to the main thread. You might be able to use it too.
:{)
:{)
Helpful and Correct tags are appreciated and help others to find information faster
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2022 06:20 AM
Hi guys,
I was rereading this after Jay's question. Getting a status of 0 usually indicates that the message was not sent. The normal HTML status codes are three digits with 200 range indicating various versions of success and 400/500 range the opposite.
You should probably make sure that you have all of your configuration options set correctly and start out with doing a basic test from there. You might also consider adding diagnostic statements to your code or follow it in debug to see if it is actually running the attempt to send, etc.
Hope that helps.
:{)
Helpful and Correct tags are appreciated and help others to find information faster
:{)
Helpful and Correct tags are appreciated and help others to find information faster