- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2022 03:03 AM
Requirement is manager of a particular group should be able to add multiple users to the selected group or remove multiple users from the selected group using catalog item.
when manager submits the request, users in "Add members to group" should be added and
users in "Remove members from group" should be removed from the group.
what should be the script in workflow("run Script").
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2022 05:39 AM
Hi,
update as this and test
var usersToAdd = current.variables.add_users; // give correct variable name here
var usersToRemove = current.variables.remove_users; // give correct variable name here
var group = current.variables.group; // give correct variable name here
var rec = new GlideRecord('sys_user_grmember');
rec.addQuery("group", group);
rec.addQuery("user", "IN", usersToRemove.toString());
rec.query();
rec.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()){
addRec.initialize();
addRec.user = arr[i];
addRec.group = group;
addRec.insert();
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2022 05:56 AM
Hi
It's working now.
Q: I want to restrict the list of field Group Members which of type List Collector and is referencing to sys_user table to show only group members of the selected group.
can this be done?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2022 06:00 AM
Hi,
Glad to know that my script worked.
Please mark my response as correct and helpful to close the thread.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2022 06:02 AM
Hi,
yes can be done via advanced ref qualifier on the User variable
you will have to query sys_user_grmember table and bring those users by passing the group sysId
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2022 11:19 PM
Hi
Thanks for the update on the question.
I have tried to "restrict the list of field Group Members which of type List Collector and is referencing to sys_user table to show only group members of the selected group"
it is working in portal view, but in native view script is not working.
Portal view:
Group Members field shows only the members of the group "AMERICAS Change Management"
Native view:
selected the same group "AMERICAS Change Management" but Group Members field is not populating the required list.
Reference Qualifier of the variable:
Script Include:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2022 11:23 PM
Hi,
should work in native as well.
Did you try adding gs.info() in script include and check if function is called or not
regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader