Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

API to get JIRA issue from Servicenow

Tamil5
Tera Expert

Hi All,

Hope you all doing good. Here is my another query,

Am not sure this is the right place to ask, but I hope if anyone can share your ideas that may divert me to the right direction.

I have referred this http://www.john-james-andersen.com/blog/service-now/rest-based-servicenow-jira-integration-poc.html and successfully integrated SNOW with JIRA.

But now I need to get the list of issues that are available in JIRA. Issues associated with a Project. I'm using MID server in my integration.

Since my GET parameter is different from (Jira Issue Search), I have created a new REST message. But it returns 'undefined' for total.

Below is my function,

getTaskDetails: function(){

var r = new RESTMessage('Jira Issue - Record Search', 'get');

r.setBasicAuth(gs.getProperty('com.snc.integration.jira.jira_api_user'), gs.getProperty('com.snc.integration.jira.jira_api_password'));

r.setStringParameter('base_url', gs.getProperty('com.snc.integration.jira.base_jira_instance_url'));

r.setXMLParameter('jqlstring', 'project=QA'); //For newer versions of an instance

r.setStringParameter('fields', 'id,key,summary,issuetype,priority,status');

if(this.midServer){

r.setMIDServer(this.midServer);

}

var response = this._executeRest(r);

var parser = new JSONParser();

var obj = parser.parse(response);

gs.log('obj.total............'+obj.total);

for (var t=0 ; t<obj.total; t++){

gs.log('tasks.key............'+obj.issues[t].key);

gs.log('tasks.self............'+obj.issues[t].self);

}

},

The Jira url,user name & password is working fine with the default REST messages. But here, obj.total returns 'undefined'.

Please help.

Thanks

Prici

1 ACCEPTED SOLUTION

Hi Ankur Bawiska,


Yes, actually it was a kind of authentication Issue. The REST Message was having some issues on the Script Include.


Made few changes   on the REST Message & I'm able make API call from Fix Script


View solution in original post

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Prici,



Did you add the rest message response to system logs and check what response you are getting from JIRA.


the value is coming as undefined may be because the response is not proper.



Regards


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur Bawiskar



The response is just Object ([Object Object]). That is the reason i tried to get the total.


Hi Prici,



print the json object in logs using JSON.stringify(); and check



Regards


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur Bawiskar,


I tried the same scripts from 'Fix script' & it is working fine.


I guess some thing went wrong when I tried the script form JiraIntegration script include. It is similar to making API calls to other applications.



Thanks


Prici