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

ADDING MORE FIELDS



To push more fields from ServiceNow to Jira, I modified the Business Rule "JiraIntegration - CreateIssue" and added my fields after line number 5 in the PoC code.



Example snippet:


var issue = {};


issue.fields = {};


issue.fields.project = {};


issue.fields.summary = ""+current.short_description;


issue.fields.description = ""+current.description;


issue.fields.issuetype = {};


issue.fields.issuetype.name=""+current.u_type; //using NAME ie. Bug = Bug, or Enhancement=Enhancement


issue.fields.customfield_10200 = ""+current.number; //informational display value only, displays PRB00010123 within Jira


issue.fields.customfield_10103 = {};


issue.fields.customfield_10103.value = ""+current.cmdb_ci.name; //pushes CI from SN


issue.fields.customfield_10111 = ""+current.opened_by.name;



A few notes about the code and process:


  • I changed the object literal declarations from the OOB (e.g. var issue = new Object();)
  • ""+current.variable casts the value to a string
  • Make sure you know if the custom field on the Jira side is a simple value (customfield_10200 above) or an object (customfield_10103 above). It's easiest to just create an issue in Jira and look at the JSON representation of the issue (e.g. https://jira.atlassian.com/rest/api/latest/issue/JRA-9) in a viewer (Notepad++ with JSTool plugin is what I use) to see the fields, current values, and structure.


WRITING TO MULTIPLE JIRA PROJECTS



Within the same file, I commented out the following line:


//issue.fields.project.key = gs.getProperty("com.snc.integration.jira.project");



I then added the following code to dynamically select which Jira project to push to based on the CI from the Problem table (yes, I changed the PoC from Incident table).



Example snippet:


var str = current.cmdb_ci.name;


var project = str.replace(/ /g, "_"); //replace all spaces with underscores



switch (project) {


  case "Accounts_Center":


  issue.fields.project.key = "AC";


  break;


  case "Payroll":


  issue.fields.project.key = "PAY";


  break;


  case "Salesforce":


  issue.fields.project.key = "SFC";


  break;


  case "System_Integration":


  issue.fields.project.key = "SI";


  break;


  default:


  issue.fields.project.key = "SER";


  break;


}




There are possibly other changes made throughout the PoC files, and I'm sure there might be better ways to accomplish these requirements, but hopefully this will help anyone who is looking to make these customizations and is unsure where to start.


Hello Gary,





I see this thread is really old. Yet, I hope that you saved your knowledge about this specific ServiceNow - to - JIRA integration.



I am currently playing with the same POC application of Mr. Andersen.
I installed it on one of my DEV ServiceNow Instances, which runs on Istanbul release.
The JIRA platform, which I am using, is a trial Cloud - based one. Due to this, I do not use a MID Server, as the JIRA is not behind any firewall.



So my scenario is slightly different than yours.


Yet, whenever I create an incident in SNOW, I am receiving the same issue as the one because of which you submitted this thread:


A corresponding JIRA Issue has been created:


ID: undefined


Issue Number: undefined


Issue URL: https://xxx.atlassian.net/browse/undefined



The Output Log of the POC does not contain any relevant information. In most of the case - no information at all, only old logs, such as:
"Executing request synchronously and directly".
Yet, in the ServiceNow Logs (System Logs > System Log > All) I see there is a communication from SNOW to JIRA.
The strange thing is that there are no error or warning messages. All messages there - are from Information Level.
What catches my eye is the following: "correlation display:.." (it is empty) & "Jira issue created: undefined".


In addition, if I go to the Incident list I see that the Correlation ID is always empty.



Following your thread, I created a custom field in JIRA and set its type to be Text Type (single line). I even created a second custom field: Text Type (multi-line),
just to ensure that I will cover all cases in regards to the Integration Setting: "Custom Field ID for ServiceNow ID". I made several tests adding the ID - s of both


the fields into this Setting. The outcome of the tests is always a negative one -> no case gets created in JIRA.



Taking under consideration the fact that I do not see any error / warning messages in my log, I am starting to think that the issue might be coming from:
- the release of my ServiceNow Instance. It runs on Istanbul, which is quite newer than the POC application (comparability issue);


- the exact URL of my trial JIRA Cloud - based version ends with .net; Or simply the fact that its trial Cloud - based one, not Server - based JIRA;


- mb I need to do any action in regards to the Correlation ID field?


- do I need to create any WebHooks in JIRA? I am currently having 3, but they are being in used for another integration with a different ServiceNow Instance
through different integration method. Is it possible the fact that I am trying to integrate the same JIRA platform with a different (more than one) ServiceNow platform
to be the problem?




Could you please let me know if I am missing something?




Cheers, Georgi




UPDATE: Not relevant anymore (check the below post for more info);


Hello Gary,





I have just managed to fixed my issue. My integration is now working fine
In my latest test I noticed that there is a message logged in the System logs of SNOW saying that "customfield is not defined".
Originally I was thinking that the system refers to the customer field which I needed to create in JIRA, so the SNOW ID to be stored there.
As mentioned above, I had two customer fields. Yet, none of them was called "customfield". So, I decided to delete my customer fields and create a new one and
name it "customfield". After doing so - the integration started working



With this said, my above post is actual anymore. So, please ignore it and Thank You again for creating this thread!
It was really useful to me!




Enjoy the weekend, Gary!





Cheers, Georgi


Hi Georgi,

I am also facing the same issue. Can you please explain what you actually did to make it work?

Thanks,

Jatinder

Hello Jatiner,




Excuse me for the delay in my response but I've just noticed you question.
In order to deal with the error message I was seeing and the issue itself - I created a custom field called: "customfield".

I mentioned all related information in my posts above.


Kind Regards,
Georgi Mavrodiev

IT Consultant 
Do IT Wise Ltd

You may visit us in our Web Site: www.doitwise.com