Service-Now Jira Rest Integration

garyopela
ServiceNow Employee
ServiceNow Employee

Much thanks to John Andersen, as always, for his stellar work on the Service-Now platform with regards to integrations.

ServiceNow integration to JIRA through REST API's-John James Andersen

 

I was wondering if anyone had any tips on this. I set this up and for some reason my service-now instance isn't able to communicate with the Jira instance. I can see in my logs whenever SN tries to send the data to jira to open a bug, I get the following returned: "Jira issue created: undefined"

 

Do I need to set up anything on the Jira side?

 

I have verified the "Jira base instance URL", the "Jira Project Key", as well as the "Custom ID for Service Now". Also I am having to use a mid-server, and I have verified it is up and running.

 

Any help would be greatly appreciated, as I have a lot more work to do on expanding this integration beyond just incident, but first I just have to get incident working.

 

Thanks!

1 ACCEPTED SOLUTION

pavel_muller
Giga Contributor

I've done a large JIRA integration based on the Andersen's code too. But I improved quite a lot there including the webhooks (used for updates from JIRA to SNC).



To debug your problems, the best way is to watch the ECC queue responses. There you can see the full JIRA response including the error messages and JSON. The Andersen's code is not very robust in terms of error handling. You will have to improve it before going into production.


View solution in original post

83 REPLIES 83

garyopela
ServiceNow Employee
ServiceNow Employee

Ahh, that is your issue then. Okay, so there is actually a pretty decent wiki article on setting up mid-servers. I have set up probably 15 or more in my environment. The following wiki article will walk you through it, and I see that now they even have a video on it.


http://wiki.servicenow.com/index.php?title=MID_Server_Installation


KB15
Giga Guru

Would it be easy to create a UI Action to send the incident to Jira instead of setting it by category? This would help create Jira incidents from existing incidents and remove the category restriction.


garyopela
ServiceNow Employee
ServiceNow Employee

Yeah, this should be totally doable. I have actually strayed away from using busineses rules like the POC uses, and then took the concept from the business rules and put them into a script include. Then you could call that script include from the UI Policy. Just bear in mind there is a bit of a delay that it takes for the jira issue to be created, so i'm not sure much about the timing that would be required.


I'm assuming that it wouldn't be as easy as copying and pasting a chunk of the code out of the business rule into the script include. So, I'm thinking that I would need a script include to create the Jira project and a UI action to call it?


garyopela
ServiceNow Employee
ServiceNow Employee

Well, it's close to that easy. First, I would highly suggest going over every line of code in the POC so that you fully understand how it works. Then you will be able to easily port the business rules over to a script include. I will give you a head start and show you my script include. Right now I'm callign it via a business rule. Here is the business rule that runs to create the jira issue (you could easily just do this part in a UI Action):


var bob = new jiraProcessor();


bob.createJira();



Then in the script include, I have this:


Name: jiraProcessor


Script:


var jiraProcessor = Class.create();


jiraProcessor.prototype = {
initialize: function() {
 
},

createJira : function() {
  var curSys = current.sys_id;
  var appl = current.variables.application.getDisplayValue();
  var reqType = current.variables.req_type;
  var issueType = current.variables.issue_type;
  var title = current.variables.title;
  var description = current.variables.description;
  var reqFor = current.request.requested_for.user_name;
  var reqDate = current.variables.requested_date;
  var comments = current.comments;
  gs.log("reqFor is : " + reqFor);
 
  var j = new JiraIntegration();
  j.debug("New Service Request has been created...create a Jira Issue");
 
  var issue = new Object();
  issue.fields = new Object();
  issue.fields.project = new Object();
  if (reqType == "Enhancement"){
    gs.log("JIRA Project is ENH");
    issue.fields.project.key = "ENH";
  } else {
    gs.log("JIRA Project is MAINT");
    issue.fields.project.key = "MAINT";
  }
  issue.fields.summary = ""+title;
  issue.fields.description = ""+description;
  issue.fields.issuetype = new Object();
  issue.fields.issuetype.name=""+issueType;
  issue.fields['customfield_'+<customfieldnumber1>] = j.getSysIdPrefix()+":"+current.sys_id;
  issue.fields['customfield_'+<customfieldnumber2>] = "sc_task"; //this allows me to run integration for multiple SN apps. Just pass this as a variable.
  issue.fields.customfield_10611 = new Object();
  issue.fields.customfield_10611 = {"value": "Flow", "child": {"value":"Scheduling"}}; //this is example of setting a multi-tiered cascading field in Jira
  issue.fields.reporter = new Object();
  issue.fields.reporter.name = reqFor;
 
  JSUtil.logObject(issue);
 
  var jiraIssue = j.createIssue(issue);
  current.correlation_id = jiraIssue.key;
  current.correlation_display = j.CORRELATION_DISPLAY;
 
  var wn = "A corresponding JIRA Issue has been created:\n";
  wn += "ID: "+jiraIssue.id+"\n";
  wn += "Issue Number: "+jiraIssue.key+"\n";
  wn += "Issue URL: "+gs.getProperty('com.snc.integration.jira.base_jira_instance_url')+"/browse/"+jiraIssue.key+"\n";
  current.work_notes = wn;
  current.update();
 
  //j.addExistingComments(current.sys_id, current.correlation_id);
},

updateComments : function(){
  var comments = current.comments;
  var issue = current.correlation_id;
 
  var j = new JiraIntegration();
  j.debug("Updating Jira Comments.");
 
 
},

modifyJira : function() {
 
},

changeStatusJira : function() {
 
},

type: 'jiraProcessor'
}



So as you can see, I really only have the part that creates the Jira issue set up for now. I have built the script include to be able to handle anything which I need to throw at it. This really just replaces the business rules, and it still relies on the script include that comes with the POC provided by Mr. Andersen.



It is set up to be dynamic enough to be able to be called form multiple places, you would just have to modify it a bit more, but for now we are just integrating it with service-request, although the integration by default is for Incident. I had them add a second custom field (denoted above by <customfield2> with the value set to "sc_task") to be able to store from which SN application this came, so that I could integrate multiple pieces with Jira.



Our long term goal is to integrate service-request, change management, and release management fully with Jira. It's ambitious, but we are taking it one steip at a time so we don't get overwhelmed.



This is a very rough draft of what the final project will look like. It works, but it's not refined and honed yet to what it will end up as, I just wanted to let you kind of see what the script include would require. Then you could call this via the UI Action and then it should flow freely from there.