Create a business rule on issues to capture the last comments or worknotes added in a custom field “Last update”.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2022 01:13 AM
Create a business rule on issues to capture the last comments or worknotes added in a custom field “Last update”.
Please share the code
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2022 01:29 AM
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.
Suresh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2022 01:50 AM
Would you mind closing your earlier question by marking my response as correct as I have already provided solution to that question.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2022 02:12 AM
Hi
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);
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2023 11:55 PM
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.