- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2015 11:18 AM
Hello all,
I am trying to collect a list of users in a service form's list collector and to remove said users from the group. I am running this script from within the workflow for the service.
The following is the script snippet I am having issues with.
var users = current.variables.users_remove.toString().split(',');
for(var i=0; i<users.length; i++){
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', current.variables.group);
//gs.log("user " + i + ": "+ users[i]);
//gr.addQuery('user', users[i]);
gr.query();
//gs.log("gr.next: " + gr.next());
if(gr.next()){ //while there are records in the recordset
var temp = gr.deleteRecord();
// gs.log("TEMP: " + temp);
}
}
The issue I am currently having is that gr.next() is returning false even though I can log the list of users from the group. If anyone could help me out with this I would be quite appreciative.
Thanks,
Jake
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2015 08:43 AM
The result of the list collector is the sys_id of that row of group membership. You will just have to delete that record, I believe.
Again, this was based on my example above, where the variable containing the list of sys_ids of group membership is called "user_test".
function deleteMultipleUsers() {
//This variable will return a list of sys_ids of group membership to delete
var users = current.variables.user_test.toString().split(',');
for(var i=0; i<users.length; i++){
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('sys_id', users[i]);
gr.query();
if(gr.next()){
gr.deleteRecord();
}
}
}
deleteMultipleUsers();
Give that a try?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2015 11:57 AM
Awesome, thanks a bunch Dylan! That ended up working out for me.