Update the fields in ServiceNow which are being updated in Jira
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-12-2022 04:16 AM
I have integrated ServiceNow with Jira. Now my requirement is whenever any field is being updated in Jira, the same should also get reflected in servicenow. For this, I am using Scripted Rest API and created webhook in Jira.
I have written the following script in Scripted Rest API, but it does not works -
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
try {
var requestBody = request.body.data;
gs.log('jiralog '+ requestBody.issue.fields.project.name);
var jr= new GlideRecord('incident');
jr.addQuery('correlation_id',requestBody.issue.key);
jr.query();
if(!jr.next())
{
jr.initialize();
jr.description=requestBody.issue.fields.description;
jr.insert();
gs.log('Jira Issue created: '+jr.correlation_id);
}
else{
jr.description=requestBody.issue.fields.description;
jr.update();
gs.log('Jira Issue updated: '+jr.correlation_id);
}
}
catch(ex) {
var message = ex.message;
}
})(request, response);
Please help me where I am wrong in this script

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-12-2022 05:18 AM - edited ‎10-12-2022 05:19 AM
Hello @Shalika
Have you checked if correlation id has correct value?
Isn't it "'requestBody.issue.fields.key", like description or project name? fields word seems missing.
Could you please check?
Please Mark ✅ Correct & Helpful, if applicable,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-15-2022 02:52 AM
Thanks for the reply.
I am able to map description and short descriptions fields correctly. How should I map the comment field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-15-2022 03:03 AM
Following is the logic I have used. I have two fields. comment_id and comment. comment id is to identify the id of last comment that was synch with the ticket.
if (JIRAData.fields.comment.comments.length > 0) {
for (var i = 0; i < JIRAData.fields.comment.comments.length; i++) {
if (jira.u_comment_id < JIRAData.fields.comment.comments[i].id) {
jira.u_comments = '\n';
jira.u_comments = JIRAData.fields.comment.comments[i].body;
jira.u_comments = 'At: ' + JIRAData.fields.comment.comments[i].updated;
jira.u_comments = 'Updated By: ' + JIRAData.fields.comment.comments[i].updateAuthor.displayName + ' [' + JIRAData.fields.comment.comments[i].updateAuthor.emailAddress + ']';
jira.u_comment_id = JIRAData.fields.comment.comments[i].id;
}
}
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2022 03:25 AM
Hii,
I am getting the data as follows --
How should I proceed with this ?