Inserting Attachments in ServiceNow from JIRA without MID-Server using REST

Rohit Kumar
Giga Expert

We were successfully able to insert attachments in ServiceNow from JIRA and hence below code can be used for other third party tools.

var targetInstanceURL =   "https://jira.******.com/secure/attachment/"+attachment ID+"/";

var targetUserID = "..";

var targetUserPassword = "...";

var sa = new GlideSysAttachment();

var StringUtil = GlideStringUtil();

var answer = "";

var attachmentMsg = {};

sendAttachments();

function sendAttachments() {

      var answer = [0, 0]; //successful attachments, failed attachments

                  //gs.log('Found a attachment##');

                      var attachmentMessage = new sn_ws.RESTMessageV2();

                      attachmentMessage.setHttpMethod("get");

                      attachmentMessage.setBasicAuth(targetUserID, targetUserPassword);

                      attachmentMessage.setEndpoint(targetInstanceURL);

                      attachmentMessage.saveResponseBodyAsAttachment("incident", current.sys_id, fileName);   // Attachment API documentation for this function

                      var response = attachmentMessage.execute();  

                    // var responseBody = response.getBody();

                      var httpStatus = response.getStatusCode();

                      if (httpStatus.toString() == "201") {

                              answer[0] += 1;

                      } else {

                              answer[1] += 1;

                      }        

      return answer;

}

I am still searching for ways to insert files in JIRA from SN without MID-Server.  

Do let me know in case of any questions !!!!

Thanks

Rohit

15 REPLIES 15

anupamg
Tera Guru

Hi Pooja

i did not use this script and came up custom script includes.

thanks

Anupam