We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

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

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  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

5 REPLIES 5

Shalika
Tera Expert

Thanks, it worked