- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2023 06:07 AM
Hi Team,
I want to know how to get the value of the person who added the worknotes to the task.
Suppose a work notes is added by system, I want to capture that ,similarly if its added by user, I want to capture the same.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2023 08:34 AM
Here is the updated script which will bring you a unique array of worknote writer on an incident.
var incident = new GlideRecord('incident'); //replace this with you task table
if (incident.get('number', 'INC0010014')) {//replace INC0010014 with your incident
var workNotes = incident.work_notes.getJournalEntry(-1);
var worknoteArray = workNotes.split('\n\n');
var worknoteWriterArray = [];
for(var i=0;i<worknoteArray.length;i++){
if(worknoteArray[i]!=''){
var worknoteWriter = worknoteArray[i].split('\n')[0].split(' - ')[1].split(' (Work')[0].trim();
if(worknoteWriterArray.indexOf(worknoteWriter)==-1){//Only add uniqe work note writer
worknoteWriterArray.push(worknoteWriter);
}
}
}
gs.info(worknoteWriterArray); // print the list of all work note writer here.
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2023 09:48 AM
Use this script to get the work note writer on an incident
var incident = new GlideRecord('incident'); //replace this with you task table
if (incident.get('number', 'INC0010014')) {//replace INC0010014 with your incident
var workNotes = incident.work_notes.getJournalEntry(-1);
var worknoteWriter = workNotes.split('\n')[0].split(' - ')[1].split(' (')[0];
gs.info(worknoteWriter);
}
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2023 11:38 AM
As you are wanting both User and System updates this will have to be server-side.
So you could just create a very simple Business Rule on the required table that is "on update" when Work Notes changes and runs something based on the below script (which I modified a little as we make heavy use of user id's:
var workNotes = current.work_notes.getJournalEntry(-1);
var worknoteWriter = workNotes.split('\n')[0].split(' - ')[1].split(' (Work ')[0];
gs.addErrorMessage("updated by: " + worknoteWriter); // or do something with the data
I just outputted to an error message for testing the value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2023 05:06 AM
Hi,
Actually our requirement is to get the user names of all the worknotes which are there in the task/incident

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2023 08:34 AM
Here is the updated script which will bring you a unique array of worknote writer on an incident.
var incident = new GlideRecord('incident'); //replace this with you task table
if (incident.get('number', 'INC0010014')) {//replace INC0010014 with your incident
var workNotes = incident.work_notes.getJournalEntry(-1);
var worknoteArray = workNotes.split('\n\n');
var worknoteWriterArray = [];
for(var i=0;i<worknoteArray.length;i++){
if(worknoteArray[i]!=''){
var worknoteWriter = worknoteArray[i].split('\n')[0].split(' - ')[1].split(' (Work')[0].trim();
if(worknoteWriterArray.indexOf(worknoteWriter)==-1){//Only add uniqe work note writer
worknoteWriterArray.push(worknoteWriter);
}
}
}
gs.info(worknoteWriterArray); // print the list of all work note writer here.
}