How To get Latest Comment On incident.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2021 01:22 AM
i want get latest comment on incident form. when incident state is In Progress and additional comment Changes.
Using Business rule GlideRecord.
1. Create Business Rule - On before update
state - In Progress.
And
Additional Comment Change
Script -:
var gr = new GlideRecord('sys_journal_field');
gr.addEncodedQuery('element=comments');
gr.addQuery('element_id', current.sys_id);
gr.addQuery('sys_created_by', '!=', current.caller_id);
gr.query();
if (gr.next()) {
current.setValue('description', gr.value);
}
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2021 02:03 AM
Hi
In your BR just add below line to get latest comments or worknotes as per your requirement
current.description=current.comments.getJournalEntry(1);
current.description=current.work_notes.getJournalEntry(1);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2021 02:07 AM
Hi,
update as this and it should work fine to get latest comments
var fieldName = 'comments';
var rec = new GlideRecord('sys_journal_field');
rec.orderByDesc('sys_created_on');
rec.addQuery('name', current.getTableName());
rec.addQuery('element', fieldName);
gr.addQuery('sys_created_by', '!=', current.caller_id.user_name);
rec.addQuery('element_id', current.sys_id);
rec.setLimit(1);
rec.query();
if(rec.next()){
current.setValue('description', rec.value);
}
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
03-21-2021 09:51 AM
Hope you are doing good.
Did my reply answer your question?
If so, please mark appropriate response as correct & helpful so that the question will appear as resolved for others who may have a similar question in the future.
Thanks!
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
03-23-2021 05:27 AM
Thank you for marking my response as helpful.
If my response helped you please mark it correct to close the question so that it benefits future readers as well.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader