- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2016 06:11 AM
Hi,
We have a request to add a group members to watchlist when it assign to a specific group. Able to fetch this data. But this is overriding the existing users of watchlist instead of appending to it.
Table: incident
When: Before
Insert:True
Update: true
Condition: Assignment group changes AND Assignment group contains "XYZ"
script:
var users=current.watch_list;
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group','sys_id');
gr.query();
while(gr.next())
{
var user =(','+ gr.user);
current.watch_list += user;
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2016 07:20 AM
Your script looks fine and should work without issues. I tested same script and it appends users to watch list. Maybe there is conflict with another script? Use Field Watcher to check for other scripts running.
Script I tested:
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group',current.assignment_group);
gr.query();
while(gr.next())
{
var user =(','+ gr.user);
current.watch_list += user;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2016 06:47 AM
I'm using below to do that.
for (var i = 0; i < rarray.length; i++) {
var recipient = rarray[i];
//Check to see if it's a user address
var gr = new GlideRecord('sys_user');
gr.addQuery('email', recipient);
gr.query();
if (gr.next()) {
// It's a user
if (wList != "") {
wList = (wList + "," + gr.sys_id);
} else {
wList = gr.sys_id;
}
} else {
//It's not a user either...so just add the address to the list...except instance email address
if (!new ArrayUtil().contains(ignoredEmailArray, recipient)) {
if (wList != "") {
wList = (wList + "," + recipient);
} else {
wList = recipient;
}
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2016 07:20 AM
Your script looks fine and should work without issues. I tested same script and it appends users to watch list. Maybe there is conflict with another script? Use Field Watcher to check for other scripts running.
Script I tested:
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group',current.assignment_group);
gr.query();
while(gr.next())
{
var user =(','+ gr.user);
current.watch_list += user;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2016 03:29 AM
Thanks for confirming on script... I had a chance to recheck business rule. My bad, there was Action set mistakenly and it was not cleared.
Script is fine. Now able to append group users to existing watch-list.
Cheers!
Krishna
