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.

Correlation ID to get the value of the ID getting from Jira

Shalika
Tera Expert

I have integrated ServiceNow and Jira. In logs of servicenow I am getting the message as

{"id":"126997","key":"SSP-8397","self":"https://neste-jira.atlassian.net/rest/api/3/issue/126997"}. 

I want this id to get populated in the correlation field of incident record.

I have the business rule as follows -

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

try{

        var sm = new sn_ws.RESTMessageV2('Neste Siili JIRA', 'POST');
        
        sm.setStringParameter("description",current.description);
        sm.setStringParameter("summary",current.number+'  '+current.short_description);
        sm.setStringParameter("reporter","614d5f6476e34d006984105b");
     
   if(current.priority == "1")
            {
                sm.setStringParameter("priority","Critical");
            }
    if(current.priority == "2")
            {
                sm.setStringParameter("priority","Major");
            }
    if(current.priority == "3" || current.priority == "4")
            {
                sm.setStringParameter("priority","Minor");
            }
   
        gs.log("hello INC Silli ");
 var response = sm.execute();
 var responseBody = response.getBody();
 var httpStatus = response.getStatusCode();
        gs.log("hello jira status"+ httpStatus);
    gs.log("hello JIRA response"+responseBody );    
    
var responseObj = (JSON.stringify(responseBody.id));
current.correlation_id = responseObj;


}
catch(ex) {
 var message = ex.message;
}
 })(current, previous);

 

I am not able to see the id value in correlation id of incident record. 

Where is my code wrong?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

update as this

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

        var jsonObj = JSON.parse(responseBody);
        current.correlation_id = jsonObj.id;

Regards
Ankur

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

View solution in original post

5 REPLIES 5

Maik Skoddow
Tera Patron
Tera Patron

Hi

the line

var responseObj = (JSON.stringify(responseBody.id));

is wrong. Instead use

var responseObj = JSON.stringify(responseBody);
var strId = responseObj.id;

Maik

 

 

Hii,

Thanks for the quick reply,

I am getting 'undefined' in logs using this

 

Ah, sorry, my bad. And I saw that Ankur already has fixed it. 

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

update as this

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

        var jsonObj = JSON.parse(responseBody);
        current.correlation_id = jsonObj.id;

Regards
Ankur

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