Update Work notes with script Include

maryam7
Tera Expert

Hi All, 

I want to get the Location field and copy in work notes on incident form . I know I can write with BR. but I would like to write with Script include. I wrote the this script include and BR. but it does not work. can you help me please . 

Script Include:

*************************************************

var UpdateWorkNotes = Class.create();
UpdateWorkNotes.prototype = {
initialize: function() {
},
location: function(usr){
var Gruser = new GlideRecord ('sys_user');
Gruser.addQuery('sys_id',usr);
Gruser.query();
if (Gruser.next()){
var location = Gruser.location.name.toString();
gs.log("user location" + location, "test");
return location;
}
},
type: 'UpdateWorkNotes'
};

********************************************************

BR: before insert or update 

var x = new UpdateWorkNotes(); //call script include
var location = x.location(current.caller_id.toString()); // set location
current.setValue('work_notes', location);

})(current, previous);

1 ACCEPTED SOLUTION

You can simplify things instead of using a script include just use:

current.work_notes = current.location.getDisplayValue();

View solution in original post

5 REPLIES 5

Mike_R
Kilo Patron
Kilo Patron

Any reason to copy to the worknotes and not use the OOTB Location field, which automatically populates with the caller's location?

no any particular reason , they just want see the current location in work note 

you have a typo in your script include

Gruser.guery();

 

it should be

Gruser.query();

thanks Mike but still does not work 

maryam7_0-1666281043547.png