Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Add name using script

umar5
Tera Contributor

Hi All,

 

I have a incident ('No : INC0001234') in that i need to add 'Florrie' into watchlist of that incident by using script. Can any one please help me with this requirement.

 

2 REPLIES 2

Vishwa Pandya19
Mega Sage

Hey,

 

If its a one time thing, you can go to Fix Script and create a new record.

You can use below script:

var inc = new GlideRecord('incident');
inc.addEncodedQuery('sys_id=<insert sys_id of your incident>');
inc.query();

if(inc.next()){
	inc.watch_list = '<insert sys_id of your user>';
        inc.autoSysFields(false);
        inc.setWorkflow(false);
	inc.update();
}

 

If my answer has helped you in any way please mark it as correct or helpful

Nishant8
Giga Sage
Giga Sage

Hello @umar5 , I assume, you'd like to update incident upon submission/update, if so you can write a BR, which runs on insert and update, and in advanced section use below script. hopefully, it should work, if not please share your problem/use case.

(function executeRule(current, previous /*null when async*/ ) {
    var userSysID = '<your sys ID>';
    var currWatchList = current.watch_list + '';
    if (currWatchList.indexOf(userSysID) == -1)
        current.watch_list = currWatchList + ',' + userSysID;
})(current, previous);
 
Regards,
Nishant