Add or remove member from the group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2023 03:42 AM
Hello All,
I have an requirement to Automate request for Add or remove member to group Item , we have two list collector fields
one is for Adding members and the other one for removing members , here my challenge is sometimes if user is already included in the group we need to Auto complete the request by adding work notes as "request already exists " in the group , need your help in understanding how we can tackle this Scenario
I have following script for adding and removing members from the group for run script
var group = current.variables.group_name;
var usersToAdd = current.variables.addmemberlist; // give correct variable name here
var usersToRemove = current.variables.removememberlist;
var grp1 = new GlideRecord('sys_user_grmember');
grp1.addQuery('group',group);
grp1.addQuery('user',usersToRemove);
grp1.query();
while(grp1.next())
{
grp1.deleteMultiple();
}
var arr = usersToAdd.toString().split(',');
for (var i = 0; i < arr.length; i++) {
var addRec = new GlideRecord('sys_user_grmember');
addRec.addQuery("user", arr[i]);
addRec.addQuery("group", group);
addRec.query();
if (!addRec.hasNext()) {
gs.info("getting into if loop");
addRec.initialize();
addRec.user = arr[i];
addRec.group = group;
addRec.insert();
}
}
can you please give some suggestion how we can develop this kind of automation
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2023 03:44 AM
you can ensure you handle this situation before submitting the catalog item
1) in the add group list collector show those groups only which user doesn't belong to
2) in the remove group list collector show only those groups to which user belongs to
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2023 03:55 AM
Hello @Ankur Bawiskar ,
you mean to do restriction in the Ref qualifier or any other? can you help me with some reference?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2023 04:15 AM
correct
apply advanced ref qualifier on both the list collector and show groups as per what I mentioned above.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2023 04:37 AM
Can I have sample reference ankur @Ankur Bawiskar