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

Hi Prici,



Were you able to print the response in logs.



Regards


Ankur


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

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


Hi Prici,



Any update on this?


Can you mark answer as correct, helpful and hit like if you were able to achieve the requirement. This helps in removing this question from unanswered list and helps users to learn from your thread. Thanks in advance.



Regards


Ankur


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

Sironi
Kilo Sage

can you help me on POST method?

 

(function executeRule(current, previous /*null when async*/ ) {

try {
var r = new sn_ws.RESTMessageV2('JIRA_POST_GET', 'POST');

 r.setXMLParameter('jqlstring', 'project=JIRASOFT');
 r.setStringParameter('issuetype', 'Task');

 r.setStringParameter('description', current.description);
 r.setStringParameter('summary', current.short_description);
 r.setStringParameter('SNOW_PRBID', current.number);
 r.setStringParameter('SNOW_SYSID', previous.sys_id);

current.u_sent_to_jira = true;

var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();

var obj = JSON.parse(responseBody);
current.u_jira_issue_id = obj.id;

current.update("Updating Sent to Jira to true");
gs.info('BR:Post to Jira:Info:' + "Created new PRB:" + current.number + ",JIRA ID: :" + obj.id);

} catch (ex) {
var message = ex.getMessage();
gs.error("Br:Post to Jira: Info :" + message);
}

})(current, previous);

 

find_real_file.png

find_real_file.pngfind_real_file.png