- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on ‎03-08-2021 12:05 AM
Hi everyone,
I thought i would write this information down somewhere as it seems as though there is information all over the place. There are many ways a serviceNow to Jira Integration can be done. One way is by using Integration Hub but this will require IntegrationHub Standard or above. Another way is by using a 3rd party tool like automate.io or zigiwave; I have never used these products so i cannot speak to them. The 3rd and final way is to build it yourself 🙂 I chose the build it yourself route, but will eventually shift to the jira spoke once i have the access. This integration can be done on any table but for this i will be focusing on the incident table.
I am going to assume you know how to set up the JIRA webhook to send comments and updates to the JIRA issue back to ServiceNow
Documents for Jira Cloud Webhook: Webhooks (atlassian.com)
I started by creating new fields on my incident form and putting them into their own tab. To be simple i called mine Create Jira Issue. I created these fields so i ca dynamically set the vales in the JSON package i send
- u_issue_key - string
- u_project_key - select box - should be mandatory
- u_jira_id - string
- u_jira_url - URL
- u_jira_team_id - hidden string field will be set by onChange client script.
- u_jira_issue - checkbox
I also created a UI policy for this as well. My UI policy displays all but one of the Jira related fields when the u_jira_issue box is set to true. I found this to be a good way to trigger my business rule. Be sure to make this field read only once true as you don't want anyone creating multiple issues in Jira for the same ServiceNow Ticket.
On the incident form the one field that is always hidden is my u_jira_team_id field. Jira sets its assignment groups by an ID number so there is a need to convert your ServiceNow Assignment group to a Jira ID number before it is sent in your JSON package to Jira. For this part, I created an onChange client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//JIRA TEAM IDs
var TeamA = "84";
var TeamB = "8";
var TeamC = "10";
var TeamD = "3";
var TeamE = "6";
var team = g_form.getValue("assignment_group");
//TeamA
if (team == "6916756fdb55d41062bb7ffb8c96195e") {
g_form.setValue("u_jira_team_id",TeamA);
//TeamB
} else if (team == "1f3ddeff6f4bde0048ed9c0cbb3ee481") {
g_form.setValue("u_jira_team_id",TeamB);
//TeamC
} else if (team == "8123e6b36f8bde0048ed9c0cbb3ee471") {
g_form.setValue("u_jira_team_id",TeamC);
// TeamD
} else if (team == "02873455371be200be66dc1873990ed5") {
g_form.setValue("u_jira_team_id", TeamD);
//TeamE
} else if (team == "02ce7f6cdbb27b808eb7776b8c961916") {
g_form.setValue("u_jira_team_id",TeamE);
//All else fails set toTeamB and they can direct
} else {
g_form.setValue("u_jira_team_id",TeamB);
}
// g_form.addInfoMessage("u_jira_team_id");
}
Atlassian has depreciated REST access via Username and password so an API key will need to be created, or You will need to set up an OAuth connection.
Documents for API Key Access: Manage API tokens for your Atlassian account | Atlassian Support
Documents for OAuth: OAuth for REST APIs (atlassian.com)
I created an onBefore Business rule with the condition of Jira issue changes to true on Insert and Update.
Under my Advanced Tab i have the following code. In the integration i have done i am opting to send the last work note that was created so the team using jira doesn't need to flip back to serviceNow to see the work notes.
I also had our Jira administrator create a couple of fields like, ServiceNow Number and ServiceNow URL on the Jira Issue screen. I wanted these fields created so There was a record of where the issue came from and a quick link back to the ServiceNow record.
(function executeRule(current, previous /*null when async*/ ) {
// create a JSON package for Jira
var notes = current.work_notes.getJournalEntry(1);
var worknoteContent = notes.split("(Work notes)\n");
var lastWorknote = worknoteContent[1].toString();
var body = {
"update": {},
"fields": {
"summary": current.number + " - " + current.short_description.toString(),
"assignee": {
"name": current.assigned_to.email.toString()
},
"reporter": current.caller,
"issuetype": {
"id": "10100" // Jira Incident
},
"project": {
"key": current.u_project_key.toString()
},
"customfield_10108": current.u_jira_team_id.toString(),
"customfield_11100": "https://myCompany.service-now.com/task.do?sys_id=" + current.sys_id.toString(),
"customfield_11001": current.number.toString(),
//Customfield 10200, 10300 10107 below are Required fields for Me but your set up may be different
"customfield_10200": {
"value": "Must"
},
"customfield_10300": {
"value": "YES"
},
"customfield_10107": {
"value": "NO"
},
"comment" : {
"body" : lastWorknote
}
}
};
var string = JSON.stringify(body); //
//gs.log('------------------->>>', string);
//Send request to JIRA endpoint
var request = new sn_ws.RESTMessageV2();
request.setEndpoint('https://myCompany.atlassian.net/rest/api/3/issue');
request.setHttpMethod('POST');
request.setRequestBody(string);
request.setRequestHeader("Accept", "application/json");
request.setRequestHeader("Content-Type", "application/json");
request.setRequestHeader("Authorization", "Basic " + "ZGFuaWVsLmNvcmRpY2tAYmBmxcmpJDFLA3DF2bmNLV0dqeGxjd0tDNkI2"); // API KEY
var response = request.execute();
gs.log(response.getBody()); //Required to update required with Issue Key and Jira ID
//Parse the response and update Incident Record
var result = JSON.parse(response.getBody());
var target = result.key;
current.u_issue_key = target;
current.u_jira_id = result.id;
})(current, previous);
If your Incident fails to create an issue in jira, check your logs for the response back. a usual error message would look something like this
{"errorMessages":[],"errors":{"customfield_10300":"Field 'customfield_10300' cannot be set. It is not on the appropriate screen, or unknown."}} |
With that, you should be able to create an issue in Jira via Business Rule. in PART 2 i will showing how i process the Webhook Event
- 3,301 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello Daniel,
Could you please suggest what to do if I receive the error in response?
{"errorMessages":[],"errors":{"customfield_10300":"Field 'customfield_10300' cannot be set. It is not on the appropriate screen, or unknown."}}
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
that error usually means, whatever custom field you have is not on the create record screen for jira. it would need to be on each view ie, create jira bug, issue, story, etc, the field would need to be on every one
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks for your response Daniel. Could you please help me to map assigned to and opened by from servicenow with assignee and reporter n JIRA? Following is the code that I've configured within the request body. However this doesn't work.
"assignee": {
"name": current.assigned_to.email.toString()
},
"reporter": {
"name": current.opened_by.email.toString(),
},
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi,
Can you help me achieve Jira integration with ServiceNow for change table?