REST API attachments Transfer to JIRA

harishdasari
Tera Guru

Hi,

We have already implemented Snow-JIRA integration and built it by our own not using the John anderson POC for snow-jira integration update set.

Requirement is we want to implement the attachment transfer from Snow to JIRA application using REST API.

I have referred lot of community articles but unable to implement it because JIRA application supports only Multipart/form-data, it will not support Binary data format for attachments.

Anyone if worked please help me with code, how they have implemented would be really helpful for lot developers.

Thank you.

20 REPLIES 20

Mike Patel
Tera Sage

I have implemented it using mid server. See my post 

https://community.servicenow.com/community?id=community_question&sys_id=3ed097a9dbdcdbc01dcaf3231f961996

Hi Mike,

 

Thanks for the response, I am not getting what is Add to Main Script Library (under Jira).  In the code which you have given in the community link.

And also I have question like what are the changes we have to make in the midserver script include because we want to hard-code the username and password of the  JIRA application in the script include.. how can I do that.. 

Thank you.

Below is code of main script. Basically you will call below script from business rule.

addExistingAttachments: function(taskID, corrID) {
		this.debug("Adding Attachments for : " + taskID);
		var attachment = new GlideRecord('sys_attachment');
		attachment.addQuery('table_sys_id', taskID);
		attachment.query();
		while (attachment.next()) {
			this._buildAttachmentRequest(attachment, taskID, corrID);
		}
	},

	_buildAttachmentRequest: function(att, taskID, corrID) {
		try {
			var sa = new GlideSysAttachment();
			var binData = sa.getBytes(att);
			var encData = GlideStringUtil.base64Encode(binData);
			var file_name = att.file_name.toString();
			var contentType = att.content_type.toString();
			this._sendAttachmentRequest(encData, file_name, contentType, corrID);
			this.debug("Adding Attachment : " + file_name + " Content-Type: " + contentType);
		} catch (Exception) {
			this.debug('Failed sending Attachment to due to Exception: ' + Exception);
		}

	},

	_sendAttachmentRequest: function(encData, file_name, contentType, corrID) {
		//Calls the MID Server Script Include
		this.debug("Calling MID Server Script Include");
		var jp = new JavascriptProbe(this.midServer);
		jp.setName("CopyAttachments");
		jp.setJavascript("var req = new CopyAttachments();");
		jp.addParameter("filePayload", encData);
		jp.addParameter("JIRA", gs.getProperty('com.snc.integration.jira.base_jira_instance_url'));
		jp.addParameter("fileName", file_name);
		jp.addParameter("contentType", contentType);
		jp.addParameter("correlationID", corrID);
		jp.setEccParameter('skip_sensor', true);
		jp.create();
	},

Hi Mike,

I am using the same code it is not working. 😞

I have put Logs in mid-server script include, actually script include itself not called during the execution. I don't find any logs for script include.

If atleast code is running, I can findout what is the issue, but the code is not running.

any clue what mistake I am making.

please help me out.

Thank you