Create a business rule on issues to capture the last comments or worknotes added in a custom field “Last update”.

sivaiah
Kilo Contributor

Create a business rule on issues to capture the last comments or worknotes added in a custom field “Last update”.

 

Please share the code

5 REPLIES 5

ersureshbe
Giga Sage
Giga Sage

Hi, Please find below code and execute in back ground script and after few changes you copy and paste in Business Rule.

var gr = new GlideRecord('sys_journal_field');
gr.addQuery('element_id',current.sys_id); // current incident sys_id
gr.addEncodedQuery(valueLIKEu_last_update);
gr.orderBy('sys_created_on');
if(gr.next()){
gs.log('Last Additional comments:'+gr.value+'CreatedOn:'+sys_created_on);
}

Please mark as correct answer if it helped.

Regards,

Suresh.

Regards,
Suresh.

Ankur Bawiskar
Tera Patron
Tera Patron

@sivaiah 

Would you mind closing your earlier question by marking my response as correct as I have already provided solution to that question.

https://community.servicenow.com/community?id=community_question&sys_id=cd70694edb3d4510a53882630596...

Regards
Ankur

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

shloke04
Kilo Patron

Hi @sivaiah 

Please write a After Update Business Rule on your table and use the script below to capture last Comment :

BR Details:

Table Name: Select the Table Name where Comment or Work note field is present

When: After Update

Condition: Comment Changes

Script:

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

	// Add your code here
	current.FIELD_NAME = current.comments.getJournalEntry(1); // Replace "Field_name" with the field where you want to copy the last comment

})(current, previous);

find_real_file.png

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Dear Shloke,

 

I have tried your code and this is working fine. 🙂

I just added 2 additional lines to make it update in the field as per the ask.

 

(function executeRule(current, previous /*null when async*/ ) {
 
  current.u_last_update = current.comments.getJournalEntry(1);
current.setWorkflow(false);
current.update();
})(current, previous);