How to get value of System or user who added the worknotes on task

Community Alums
Not applicable

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.

1 ACCEPTED SOLUTION

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.
}

View solution in original post

4 REPLIES 4

Sandeep Rajput
Tera Patron
Tera Patron

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. 

Ian Mildon
Tera Guru

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.

 

Community Alums
Not applicable

Hi,

Actually our requirement is to get the user names of all the worknotes which are there in the task/incident

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.
}