How can I get all list of work notes in incident?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2022 11:11 PM
I have created a button on incident using UI Action, it suppose to get all the value of work notes after clicking it.
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2022 11:17 PM
Hi,
you can take 2 approaches
Approach 1: query sys_journal_field
var arr = [];
var gr = new GlideRecord("sys_journal_field");
gr.addQuery("name", "incident");
gr.addQuery("element", "work_notes");
gr.query();
while (gr.next()) {
arr.push(gr.getValue('value'));
}
gs.addInfoMessage("All work notes " + arr.toString());
OR
Approach 2: UI Action should be server side
var notes = current.work_notes.getJournalEntry(-1);
//stores each entry into an array of strings
var na = notes.split("\n\n");
for (var i = 0; i < na.length; i++)
gs.addInfoMessage(na[i]);
regards
Ankur
Regards,
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2022 04:49 AM
Hi Laida,
Following script will get the worknotes for the current incident.
var grIncident = new GlideRecord('sys_journal_field');
grIncident.addEncodedQuery('GOTOname=incident^element=work_notes^element_id=' + current.sys_id);
grIncident.orderBy('sys_created_on');
grIncident.query();
var workNotesArray = [];
while (grIncident.next()) {
workNotesArray.push(grIncident.getValue('value').toString());
}
gs.info(workNotesArray);