Add recruiter to watchlist

HiranamyeeM
Tera Contributor

Hi All !

 

Add the recruiter in the watchlist in HR case table automatically.

 

Wrote a BR, but not working. kindly help !

 

TIA

 

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

var recruiterID = current.u_recruiter.toString();

if (!recruiterID) {
return;
}

var watchList = current.watch_list.toString();

// 3. Add the recruiter to the watchlist if they aren't already on it
if (watchList.indexOf(recruiterID) === -1) {
if (watchList.length > 0) {
current.watch_list = watchList + ',' + recruiterID;
} else {
current.watch_list = recruiterID;
}
}
})(current, previous);

 

 

1 REPLY 1

Tanushree Maiti
Giga Patron

Hi @HiranamyeeM 

 

Try with Before Update Business Rule with Proper trigger condition.

Script:

 

(function executeRule(current, previous /*null when async*/) {
var recruiterID = current.u_recruiter.toString();
if (recruiterID)

 {
  var watchlist = current.watch_list ? current.watch_list.split(',') : [];

            if (watchlist.indexOf(recruiterID) == -1)

            {

                watchlist.push(recruiterID);

                current.watch_list = watchlist.join(',');

            }

}
})(current, previous);

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin: