- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2016 11:21 AM
Hi Everyone,
I would like to add in a check box on my incident form to notify a Specific Group.
Pseudo Code -
Where: Incident
When: Insert and Update
If "Notify_Management" changes to True, add "Manager" group to the watch list.
Could someone share a script for this based on the info above?
Thank you
Carl
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2016 10:10 AM
Copy the following script as is in the Business rule. I have tested this and it works. Just replace the highlighted portion with your group name
(function executeRule(current, previous /*null when async*/) {
var members=[];
var gr= new GlideRecord('sys_user_grmember');
gr.addQuery('group.name','Your group name'); //put your group name here
gr.addQuery('user.active',true);
gr.query();
while(gr.next()){
members.push(gr.getValue('user'));
}
var new_memb='';
if(current.watch_list.toString().length>0)
new_memb=current.watch_list.toString()+','+members.join();
else
new_memb=members.join();
current.watch_list=new ArrayUtil().unique(new_memb.split(',')).join();
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2016 08:02 AM
Also line 7 does not look correct, you need to open up a bracket for your while loop and close it.
(function executeRule(current, previous /*null when async*/) {
var members=[];
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group.name','ITSM - Systems Admin');
gr.addQuery('user.active',true);
gr.query();
while(gr.next()) {
members.push(gr.getValue('sys_id'));
}
var new_memb = current.watch_list.toString()+','+members.join();
current.watchlist = new_memb;
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2016 08:47 AM
Thank you, I pasted what you provided in to my business rule but it's still not setting it.
(function executeRule(current, previous /null when async/) {
var members=[];
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group','ITSM - Systems Admin');
gr.addQuery('user.active',true);
gr.query();
while(gr.next()) {
members.push(gr.getValue('sys_id'));
}
var new_memb = current.watch_list.toString()','members.join();
current.watchlist = new_memb;
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2016 08:49 AM
Looks like this line is missing the + sign to join those strings.
var new_memb = current.watch_list.toString()+','+members.join();
I would suggest writing some gs.log messages to see if you can track where your script is failing. Put one at the top to see if the business rule is even running, and then take it from there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2016 09:05 AM
Thanks. I don't know javascript so I am at the mercy of the community for now. I appreciate your help and time though.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2016 07:59 AM
Two updates to the script in your screenshot:
gr.addQuery('group.name','ITSM - Systems Admin');
and
while(gr.next()) {
- Hardik Vora