- 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
05-29-2015 08:48 AM
Here is my latest version of the code:
function deleteMultipleUsers() {
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);
gr.addQuery('user', users[i]);
gr.query();
if(gr.next()){
gr.deleteRecord();
}
}
}
deleteMultipleUsers();
Thanks for taking a look at this for me!
- Jake
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2015 10:34 AM
Hello Jacob,
Is it removing any users from the group?
Try to log users and group values.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2015 11:14 AM
If I log the users I get a sysId for each user, so I don't believe it's a problem with obtaining and using the list of the users, however, my query is still failing for some reason.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2015 11:47 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2015 12:03 PM
Are you getting the group correctly? Add a log for group. Are the users included in the group which is there on the current record?