---
title: "Common Document Integrations - ServiceNow <> Jira"
canonical: "https://docs.perspectium.com/space/earlierReleases/1442146/Common%20Document%20Integrations%20-%20ServiceNow%20%3C%3E%20Jira"
format: markdown
---
This is a legacy feature so it has restricted permissions for Perspectium employees only - it is intended for internal use with customers on a need-by-need basis.  Common Change Because ServiceNow change requests are generally mapped with Jira's story and epic issue types, an  issue_type  attribute should be created in your ServiceNow's outbound   table map. For example, if you want to map your change to a Jira story, you would create a table map to set the  issue_type  attribute to  Story : For Epic, you would set up the above to have: answer = 'Epic'; Common Request Update Sets To begin using the common request format in your ServiceNow - Jira integrations, you must make sure your integration is  properly set up . Then,  install the latest Perspectium Common Request update set, which you can request from Perspectium Support. Outbound Table Map In order for the ServiceNow to Jira direction to work, you need to set up an outbound table map. You need to create a separate outbound table map for each integration you want to do. Go to  Perspectium - Table Maps  and create a new outbound table map like so (for this example we will use the  sc_task  table as the source table): Then, click  Add all source table fields  to map fields from the source table to the common request format. You can customize this table map and the field maps as you wish or leave it as is, however there are several field maps that must be created as specified below for records to be properly created in a Jira: Create a field map with   Source Field   as   ${TM:psp_attachment;table_sys_id=$[GR:sys_id];jira_sent} ,   Target Field   as   attachments ,   Use Script   as   false , and   Field Type   as   String . Create a field map with  Source Field  as  CorrelationId , Target Field  as  @CorrelationId , Use Script  as  true , and  Field Type  as  String . Set the  Source Script  to: answer = current.correlation_id; Create a field map with   Source Field   as   IssueType ,   Target Field   as   @issue_type ,   Use Script   as   true , and   Field Type   as   String . Set the   Source Script to: answer = "Request"; Create a field map with Source Field as JiraProject , Target Field as @JiraProject , Use Script as true , and Field Type as String . Set the Source Script to: answer = gs.getProperty("com.perspectium.siam.jira.project"); Create a field map with Source Field as priority , Target Field as priority , Use Script as true , and Field Type as String . Set the Source Script to whatever you like to map your priorities to Jira priorities or use this example snippet of code: if (current.priority == "1") {
	answer = "Priority 1";
} else if (current.priority == "2") {
	answer = "Priority 2";
} else {
	answer = "Priority 3";
} Create a field map with Source Field as provider , Target Field as provider , Use Script as true , and Field Type as String . Set the Source Script to: answer = "servicenow"; You also need to set up a tag for attachments to work. Create a tag in the  label  table (type  label.list  in the Filter Navigator box to quickly go to the  label  table) and name it  jira_sent : Transform Map The next step is to setup a transform map to take care of Jira to ServiceNow mappings. Go to  System Import Sets  >  Transform Maps  and create a new transform map. This transform map should use the PSP Common Request import set table ( u_psp_common_request ) as the source table and the target table should be the ServiceNow table you are integrating Jira with and previously created the outbound table map for ( sc_task  in this example). Make sure to check the   Run script   box and add the script displayed in the picture and below: (function transformRow(source, target, map, log, isUpdate) {

	if (isUpdate == true) {
		target.psp_subscribed_record = true;
	}

})(source, target, map, log, action==="update"); This script is needed so that when fields are updated in Jira and sent as a message to ServiceNow, the ServiceNow instance will not update itself and send a duplicate update message back to Jira again. Once you have created the transform map, click on   Auto Map Matching Fields   under   Related Links . The field maps will automatically populate. Click into the field map with   Source field   u_number   and   Target field   number   and check   Coalesce   and   Coalesce empty fields .  Finally, go to the   Transform Scripts   tab and create a new script like such: and in the script box add the following code snippet and submit (but replace  sc_task  with your desired table): (function runTransformScript(source, map, log, target) {
	var logger = new PerspectiumLogger();
	logger.logDebug('onAfter processing - action:' + source.u_action, null, null);

	if (source.u_action == 'issue_created') {
		var pspR = new PerspectiumReplicator();
		var ds = new GlideRecord("psp_replicate_conf");
		ds.addQuery("u_target_queue.u_name", "psp.in.siam.client.jira");
		ds.addQuery("active", "true");
		ds.addQuery("sync_direction", "share");
		ds.query();
		if (ds.next()) {
			if (!source.u_number.nil() && !source.u_correlation_id.nil() && !source.u_correlation_display.nil()) {
				var pspS = new PerspectiumEncryption();
				var ogr = new GlideRecord("psp_out_message");
				ogr.addQuery("state", "deferred");
				ogr.addQuery("u_extra", "CONTAINS", "number=" + source.u_number);
				ogr.query();
				while (ogr.next()) {
					// update value with correlation id before we send out
					var decodeData = pspS.decryptString(ogr.value);
					decodeData = decodeData.replace("<correlation_id/>", "<correlation_id>" + source.u_correlation_id + "</correlation_id>");
					decodeData = decodeData.replace("<correlation_display/>", "<correlation_display>" + source.u_correlation_display + "</correlation_display>");

					ogr.value = pspS.encryptStringWithCipher(decodeData, "3");
					ogr.u_extra = "";
					// also need to update the correlation_id in the attributes for it update properly
					ogr.u_attributes = String(ogr.u_attributes).replace("CorrelationId=,", "CorrelationId=" + source.u_correlation_id + ",");					
					ogr.state = "ready";
					ogr.update();
				}
			}
		}
	}
	
	if (source.u_action == 'issue_created') {
		var grc = new GlideRecord("sc_task");
		grc.addQuery("correlation_id", source.u_correlation_id);
		grc.query();
		if (grc.next()) {
			grc.update();
		}
	}
	
	if (source.u_action == 'issue_updated' || source.u_action == 'issue_created') {
		var attachments = new PerspectiumAttachment();
		attachments.addAttachments(source, target, "jira_sent");
	}
	
	if (source.u_action == 'issue_deleted') {
		var grd = new GlideRecord("sc_task");
		grd.addQuery("number", source.u_number);
		grd.query();
		if (grd.next()) {
			logger.logDebug('onAfter issuing delete of number:' + source.u_number, null, null);
			grd.deleteRecord();
		}	
	}
})(source, map, log, target); This script is used for several different things, including sending attachments to Jira and deleting records in ServiceNow when an issue is deleted in Jira. It is also used to send a message back to Jira so that it knows the corresponding ServiceNow number. This is because when an issue is created in Jira, it needs something to correlate with the matching ServiceNow record that is created. Shared Queue Create a shared queue with the name   psp.in.siam.client.jira   and set the   Endpoint URL   to your MBS cluster URL   and set the proper credentials. Dynamic Share Create a new dynamic share for the table that you are using (sc_task in the example). Make sure   Active   is checked and then check any other options you want for the dynamic share. Set   Target queue   to   psp.in.siam.client.jira   and   Table map   to the table map you made in step 2. Make sure that   Include attachments   and   Interactive only   are NOT checked. If you have not already done so, once you are done with installation and configuration you will need to contact Perspectium Support so that your MBS cluster can be properly configured.