- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2020 06:46 PM
I am trying to integrate ServiceNow with Jira and worked out how to sync new ticket create in Jira when new incident created in ServiceNow through Scripted REST API. It works fine, but i still could not figure out how update comments in both direction.
I tried webhook, connection works fine between ServiceNow and Jira. When Jira tickets updated new response sent to SNOW and I can see it under logs in JSON format. but I don't know how to get values from this response body and fetch into relevant ServiceNow tickets under comment field.
I really appreciated if someone can help me here:
Json response body:
{"timestamp":1589671258662,"webhookEvent":"comment_created","comment":{"self":"https://Jirasnowintegration.atlassian.net/rest/api/2/issue/10060/comment/10000","id":"10000","author":{"self":"https://Jirasnowintegration.atlassian.net/rest/api/2/user?accountId=5ea23ec8c0b45b0c17a88675","accountId":"5ea23ec8c0b45b0c17a88675","avatarUrls":{"48x48":"https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/5ea23ec8c0b45b0c17a88675/e4ab785d-60d3-4f7e-8627-650abcd42289/128?size=48&s=48","24x24":"https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/5ea23ec8c0b45b0c17a88675/e4ab785d-60d3-4f7e-8627-650abcd42289/128?size=24&s=24","16x16":"https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/5ea23ec8c0b45b0c17a88675/e4ab785d-60d3-4f7e-8627-650abcd42289/128?size=16&s=16","32x32":"https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/5ea23ec8c0b45b0c17a88675/e4ab785d-60d3-4f7e-8627-650abcd42289/128?size=32&s=32"},"displayName":"Han Ata","active":true,"timeZone":"Australia/Sydney","accountType":"atlassian"},"body":"I have broken mouse","updateAuthor":{"self":"https://Jirasnowintegration.atlassian.net/rest/api/2/user?accountId=5ea23ec8c0b45b0c17a88675","accountId":"5ea23ec8c0b45b0c17a88675","avatarUrls":{"48x48":"https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/5ea23ec8c0b45b0c17a88675/e4ab785d-60d3-4f7e-8627-650abcd42289/128?size=48&s=48","24x24":"https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/5ea23ec8c0b45b0c17a88675/e4ab785d-60d3-4f7e-8627-650abcd42289/128?size=24&s=24","16x16":"https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/5ea23ec8c0b45b0c17a88675/e4ab785d-60d3-4f7e-8627-650abcd42289/128?size=16&s=16","32x32":"https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/5ea23ec8c0b45b0c17a88675/e4ab785d-60d3-4f7e-8627-650abcd42289/128?size=32&s=32"},"displayName":"Han Ata","active":true,"timeZone":"Australia/Sydney","accountType":"atlassian"},"created":"2020-05-17T09:20:58.662+1000","updated":"2020-05-17T09:20:58.662+1000","jsdPublic":true},"issue":{"id":"10060","self":"https://Jirasnowintegration.atlassian.net/rest/api/2/10060","key":"CAD-58","fields":{"summary":"Test test","issuetype":{"self":"https://Jirasnowintegration.atlassian.net/rest/api/2/issuetype/10001","id":"10001","description":"Functionality or a feature expressed as a user goal.","iconUrl":"https://Jirasnowintegration.atlassian.net/secure/viewavatar?size=medium&avatarId=10315&avatarType=issuetype","name":"Story","subtask":false,"avatarId":10315},"project":{"self":"https://Jirasnowintegration.atlassian.net/rest/api/2/project/10000","id":"10000","key":"CAD","name":"CAD","projectTypeKey":"software","simplified":false,"avatarUrls":{"48x48":"https://Jirasnowintegration.atlassian.net/secure/projectavatar?pid=10000&avatarId=10409","24x24":"https://Jirasnowintegration.atlassian.net/secure/projectavatar?size=small&s=small&pid=10000&avatarId=10409","16x16":"https://Jirasnowintegration.atlassian.net/secure/projectavatar?size=xsmall&s=xsmall&pid=10000&avatarId=10409","32x32":"https://Jirasnowintegration.atlassian.net/secure/projectavatar?size=medium&s=medium&pid=10000&avatarId=10409"}},"assignee":null,"priority":{"self":"https://Jirasnowintegration.atlassian.net/rest/api/2/priority/3","iconUrl":"https://Jirasnowintegration.atlassian.net/images/icons/priorities/medium.svg","name":"Medium","id":"3"},"status":{"self":"https://Jirasnowintegration.atlassian.net/rest/api/2/status/10000","description":"","iconUrl":"https://Jirasnowintegration.atlassian.net/","name":"Backlog","id":"10000","statusCategory":{"self":"https://Jirasnowintegration.atlassian.net/rest/api/2/statuscategory/2","id":2,"key":"new","colorName":"blue-gray","name":"To Do"}}}}}
Solved! Go to Solution.
- Labels:
-
Integrations

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2020 07:37 PM
try below
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var body = JSON.stringify(request.body.data);
var parser = new JSONParser();
var parameterArr = parser.parse(body);
var gr = new GlideRecord("incident");
gr.addQuery("u_jira_issueid", parameterArr.issue.key);
gr.query();
if (gr.next()) {
gr.work_notes = 'Commented by: ' + parameterArr.comment.author.displayName + '\nComment: '+ parameterArr.comment.body;
gr.update();
//gs.log(parameterArr.comment.body);
}
})(request, response);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2020 08:05 PM
I made few changes and works fine now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2020 08:18 PM
That was so quick.
I really appreciated your tireless effort to help me out here.
I learned a lot through this integration with your help, also following Mr.John Anderson videos to up skill my knowledge.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2020 08:22 PM
It works fine.
I will clean the code and add into this thread for other community members to get benefits.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2022 05:37 PM
Hi
I was updating the incident in SN when issue changes in JIRA, so I am synching the comments and description, I get to do that, but the updated by is "guest". Is it really like this? I was hoping like its going to be updated by system, or an API user account.. Also the updated by is "guest"...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2020 10:55 PM
This is the code for ServiceNow comment sync to Jira record.
Rest message:
Business rule:
(function executeRule(current, previous /*null when async*/ ) {
var comments = {};
comments.body = current.comments.getJournalEntry(1);
var issueKey = current.u_jira_issueid;
try {
var r = new sn_ws.RESTMessageV2('Jira Testing Demo', 'Post');
r.setStringParameterNoEscape('issueKey', issueKey);
r.setStringParameterNoEscape('base_endpoint', 'https://jiraandesta.atlassian.net'); //works
r.setStringParameterNoEscape('commentBody', JSON.stringify(comments));
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
} catch (ex) {
var message = ex.message;
}
gs.log("HTTPCODE:" + httpStatus + "BODY:" + current.number + response.getBody());
gs.log(message.getBody());
gs.log("last comments through variable:" + comments.body);
gs.log("IssueKey:" + issueKey.key);
//gs.log("LAST COMMENT: " + current.comments.getJournalEntry(1));
//gs.log(r.getBody());
})(current, previous);