Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

I am getting a HTTP status 0 while making an rest call from servicenow to servicenow instance

Arundhati
Tera Contributor

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);

5 REPLIES 5

Miguel Pacheco
Tera Contributor

I'm getting same issue here, did anyone found a solution for this?