- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2022 03:36 AM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2022 04:31 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2022 03:53 AM
Hi
the line
var responseObj = (JSON.stringify(responseBody.id));
is wrong. Instead use
var responseObj = JSON.stringify(responseBody);
var strId = responseObj.id;
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2022 04:27 AM
Hii,
Thanks for the quick reply,
I am getting 'undefined' in logs using this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2022 04:47 AM
Ah, sorry, my bad. And I saw that Ankur already has fixed it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2022 04:31 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader