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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2017 04:43 AM
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
- Labels:
-
Integrations
-
Scripting and Coding
- 9,449 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2019 08:22 PM
Hi tmackay
We are also building the custom scripts to send attachments to Jira from SN without using MID server. So far we are successful in sending .txt and .csv file but not the the word or excel file docs. .JPG and .PDF files we are able to send but not able to open at JIRA.
We tried downloading your file jira_script_include_b64.txt but could not do so, probably because it is an old attachment.
Any help is greatly appreciated.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2019 10:21 PM
Hi anupamg,
Strange, I can still download the attachment. That aside, I wouldn't recommend that approach any more. What I've settled on is creating a Scripted REST resource which uses response.getStreamWriter() to construct the request body in suitable binary format for JIRA and the built-in RESTMessageV2.saveResponseBodyAsAttachment to save this as an attachment to the original attachment, then we pass it to Jira using setRequestBodyFromAttachment in the final RESTMessageV2. No need to stuff around with base64 intermediates - which was a bit of a hack to begin with. All the necessary code for the new approach is in this thread.
Regards,
Troy.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2019 09:42 AM
Thanks tmackay for the suggestions. We are able to resolve our issues with Jira & SN attachments..
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2020 10:53 PM
Hi anupamg,
How were you able to resolve same as I am facing same issues. Whenever I upload the attachment as PDF (via script in Virtual Agent) to service now table record. I am able to see the attachment n PDF format but can't view it after download as it fails to load. Any hints as to how you resolved similar issue would be helpful for me. Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2019 06:19 AM
Could you please help where can I use this code