JIRA integration: Passing Work notes as Comments

NehaSNOW
Tera Guru

Dear Members,

 

Requirement: - Sending Work notes as Comment via REST API to JIRA.

Implementation: - I have created the below Business rule which runs on Insert/Update of an Incident and also a REST API.

Issue: - Getting the error JIRA Comments: {"errorMessages":["There was an error parsing JSON. Check that your request body is valid."]} in the System Log. However, the Comment in the JIRA gets created when parameters are passed directly from the Outbound REST API Message.

Release: - Xanadu

Please suggest.

 

 

NehaSNOW_0-1737629267861.png

 

Outbound REST API Message: - https://<confidential>.atlassian.net/rest/api/3/issue/${correlation_id}/comment

NehaSNOW_1-1737629596167.png

 

Thanks,

Neha

 

12 REPLIES 12

@NehaSNOW 

the issue is with the way how getJournalEntry(1) gives the value and the work notes contain special character which JIRA might not be handling

Do this

1) remove the POST Content field and set the Request body via script

Something like this if it works

 var comments = current.comments.getJournalEntry(-1);

 var body = '{"body":{"content":[{"content":[{"text":"${work_notes}","type":"text"}],"type":"paragraph"}],"type":"doc","version":1}}';
 body = body.replace("${work_notes}", current.comments.getJournalEntry(1).toString());
 var finalbody = JSON.stringify(body);
 r.setRequestBody(finalbody);
 var response = r.execute();

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar 

 

I have modified the code with your recommendation as follows but still getting the error in response: -

 

(function executeRule(current, previous /*null when async*/) {

 //var work_notes = current.work_notes.getJournalEntry(-1);
 //gs.log('WORK NOTES: '+ work_notes);
 var body = '{"body":{"content":[{"content":[{"text":"${work_notes}","type":"text"}],"type":"paragraph"}],"type":"doc","version":1}}';

 body = body.replace("${work_notes}", current.work_notes.getJournalEntry(1).toString());

 var r = new sn_ws.RESTMessageV2('JIRA Integration - Incident', 'Add Comment in JIRA');
 
 r.setStringParameterNoEscape('correlation_id', current.u_correlation_id);
 //r.setStringParameterNoEscape('worknotes', work_notes);

 var finalbody = JSON.stringify(body);

 gs.log('Final Body: '+ finalbody);
 r.setRequestBody(finalbody);
 var response = r.execute();

 gs.log('correlation_id: '+ current.u_correlation_id);

 //var response = r.execute();
 var responseBody = response.getBody();
 var httpStatus = response.getStatusCode();
 gs.log('JIRA Comments: '+ responseBody);

})(current, previous);
 
Log: -
NehaSNOW_0-1737635021335.png

 

@NehaSNOW 

seems issue with your BR and retrieving the value from journal field

BR logs are coming?

Are you updating the comment as admin or non-admin?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar Yes, the issue seems with retrieving the value from Journal field and passing it to the Outbound REST Message. 

Yes, BR logs are coming and I am updating the comment as an Admin.

My modified BR but still getting the same error:-

NehaSNOW_0-1737650250009.png

 

Error: -

NehaSNOW_1-1737650282445.png

 

@NehaSNOW 

very difficult to debug without having the actual access to the instance.

Is this happening all the time?

this is for incident table right?

Also it's strange as you are getting the work notes in logs but unable to send although hard-coding the same work notes work in BR

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader