The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Update the fields in ServiceNow which are being updated in Jira

Shalika
Tera Expert

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

6 REPLIES 6

Community Alums
Not applicable

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,

Thanks for the reply.

I am able to map description and short descriptions fields correctly. How should I map the comment field 

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.

Hii,

I am getting the data as follows --

Shalika_0-1666002313150.png

 

 

How should I proceed with this ?