How do I automatically add the opened by field user to the watch list and work notes list on a record producer?

KB3
Kilo Explorer

I'm trying to figure out how do I automatically add users from the opened by field to the watch list on a record producer. I'm using the code below but I'm a little stuck at this point. Any help is needed. I'm new to scripting 

 

current.watch_list = opened_by;
current.work_notes_list = opened_by;

2 REPLIES 2

Aman Kumar S
Kilo Patron

Hey,

Write up a before business rule on the incident table 

(function executeRule(current, previous /*null when async*/ ) {

  
    var opened = current.getValue("opened_by");
    current.watch_list = opened;
    current.work_notes_list =opened;

})(current, previous)
Best Regards
Aman Kumar

Hitoshi Ozawa
Giga Sage
Giga Sage

KB,

This is a duplicate of the following question.

https://community.servicenow.com/community?id=community_Question&sys_id=a458ca451b1fcd10b09633f2cd4b...

ServiceNow community clearly states not to post the same question to several forums.

Be sure to post in the most relevant forum. Do not post the same post in several forums.

https://community.servicenow.com/community?id=community_article&sys_id=883c2661dbd0dbc01dcaf3231f961...

As I've answered in the other thread, try the following.

Filter Conditions: "Opened by" "is not empty"

(function executeRule(current, previous /*null when async*/) {
	var openedBy = current.opened_by;
	if (!current.watch_list.includes(openedBy)) {
		current.watch_list += ',' + openedBy;
	}
	if (!current.work_notes_list.includes(openedBy)) {
		current.work_notes_list += ',' + openedBy;
	}
})(current, previous);