How to retrieve the contents of work_notes in the incident table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2024 02:57 AM
Hello. - Hello.
I am looking for a way to get the latest content about the "work_notes" entry in the incident table. I am trying to write the source to a script include, but I would like to know if there are other methods.
For example, if the latest entry for "work_notes" is "Test 1 was executed", I would like to get "Test 1 was executed" as a value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2024 03:30 AM - edited 03-28-2024 02:07 AM
Hi @yui ozo,
This can easily be achieved by leveraging the following syntax and method via a business rule (if appropriate - I know you've mentioned a ScriptInclude):
var notes = current.work_notes.getJournalEntry(-1); //gets all journal entries as a string where each entry is delimited by '\n\n'
var na = notes.split("\n\n");
If using a ScriptInclude, you'll just have to make sure you pass the sys_id of the record from where you want to obtain the work notes from.
If it's any help, you can also perform a GlideRecord on the journal field as below, but leveraging the work_notes.getJournalEntry(-1) does a lot for you already ; )
var workNotesGR = new GlideRecord('sys_journal_field');
workNotesGR.addQuery('element_id', sys_id); //Pass the sys_id of the record here
workNotesGR.addQuery('name','task');
workNotesGR.orderByDesc('sys_created_on');
workNotesGR.setLimit(1);
workNotesGR.query();
while(workNotesGR.next() ) {
gs.print( workNotesGR.element + ' = ' + workNotesGR.value );
}
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2024 03:43 AM
Script Include:
var WorkNotesUtil = Class.create();
WorkNotesUtil.prototype = {
initialize: function() {},
getLatestWorkNote: function(incidentSysId) {
var workNote = '';
var gr = new GlideRecord('sys_journal_field');
gr.addQuery('element_id', incidentSysId);
gr.addQuery('element', 'comments');
gr.orderByDesc('sys_created_on');
gr.setLimit(1);
gr.query();
if (gr.next()) {
workNote = gr.getValue('value');
}
return workNote;
},
type: 'WorkNotesUtil'
};
You can then use this script include function in your client scripts, business rules, or other server-side scripts to retrieve the latest "work_notes" entry.
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2024 08:43 AM - edited 03-28-2024 02:05 AM
Hi @yui ozo,
Did you see my earlier response?
This can easily be achieved by leveraging the following syntax and method via a business rule (if appropriate - I know you've mentioned a ScriptInclude):
var notes = current.work_notes.getJournalEntry(-1); //gets all journal entries as a string where each entry is delimited by '\n\n'
var na = notes.split("\n\n");
If using a ScriptInclude, you'll just have to make sure you pass the sys_id of the record from where you want to obtain the work notes from.
If it's any help, you can also perform a GlideRecord on the journal field as below, but leveraging the work_notes.getJournalEntry(-1) does a lot for you already ; )
var workNotesGR = new GlideRecord('sys_journal_field'); workNotesGR.addQuery('element_id', sys_id); //Pass the sys_id of the record here workNotesGR.addQuery('name','task');
workNotesGR.orderByDesc('sys_created_on');
workNotesGR.setLimit(1); workNotesGR.query(); while(workNotesGR.next() ) { gs.print( workNotesGR.element + ' = ' + workNotesGR.value ); }
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.
Thanks, Robbie