
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-29-2017 11:24 AM
Hey all,
I am working on a script for a Run Workflow activity and am stuck. Here is an overview:
User submits a form on the Portal that creates a RITM. When they Select the option "Remove Access" another field pops up with a list of the current groups they are in. They can select which group or groups they want to have access removed from and then submit the form. The workflow is set up such as if they request removal from group(s) they are members of, there is no approval needed and the system can go ahead with the automation and remove them. I have all of that stuff figured out, its the script I am stuck on.
Here is what I have so far, admittedly I am not terribly experienced with scripting so I may be going in the totally wrong direction:
var grpRemove = new GlideRecord('sys_user_grmember');
grpRemove.addQuery('user', current.variables.requester_name.sys_id);
grpRemove.addquery('group.name', current.variables.var_groups_removal);
grpRemove.query();
if(grpRemove.next()) {
grpRemove.deleteRecord();
}
I am thinking I need a way for it to remove the users from more than one group if they select more than one, but I was just trying to get it to remove them from one first and then build on it from there. I have tried a few variations and changes on the above script but no luck so far. Any help would be appreciated!
Thanks!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-29-2017 03:15 PM
OK,
Got it working after much trial and error and enlisting the help from a fellow developer on a Skype meeting 😃 Want to post here to complete the question and for anyone else who may run in to this in the future. What we ended up having to do with the script is as follows:
var grps = current.variables.var_groups_removal.toString().split(',');
var grpRemove = new GlideRecord('sys_user_grmember');
grpRemove.addQuery('user', current.variables.requester_name);
var groups = grpRemove.addQuery('group', grps[0]);
for (var i = 1; i< grps.length;i++)
groups.addOrCondition('group', grps[i]);
grpRemove.query();
while(grpRemove.next()) {
grpRemove.deleteRecord();
}
var removed = current.variables.var_groups_removal.getDisplayValue();
current.comments = "The user has been successfully removed from the following groups: " + removed;
Thanks all for the help and suggestions with this, definitely made it easier!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-29-2017 01:44 PM
Sanjiv,
See above, I tried this as well and it doesn't pull the request from any of the user groups

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-29-2017 03:15 PM
OK,
Got it working after much trial and error and enlisting the help from a fellow developer on a Skype meeting 😃 Want to post here to complete the question and for anyone else who may run in to this in the future. What we ended up having to do with the script is as follows:
var grps = current.variables.var_groups_removal.toString().split(',');
var grpRemove = new GlideRecord('sys_user_grmember');
grpRemove.addQuery('user', current.variables.requester_name);
var groups = grpRemove.addQuery('group', grps[0]);
for (var i = 1; i< grps.length;i++)
groups.addOrCondition('group', grps[i]);
grpRemove.query();
while(grpRemove.next()) {
grpRemove.deleteRecord();
}
var removed = current.variables.var_groups_removal.getDisplayValue();
current.comments = "The user has been successfully removed from the following groups: " + removed;
Thanks all for the help and suggestions with this, definitely made it easier!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2019 07:53 AM
Hi All,
I have implemented this script with great success. Thank you to all contributors. What I would like to have accomplish is a line of code that will exclude this script from taking action on the 'Admin' group or the 'admin role'. Please help.