- 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-27-2022 02:33 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2022 02:59 AM
Hi,
that should not happen but you can ignore it.
But it should work fine in both native + portal
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-27-2022 03:02 AM
Hi
but in native view, list is not filtering and showing as none.
how can this be achieved in native view?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2022 04:05 AM
The similar solution has worked for me in past in both native + portal
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2023 06:49 AM
We are trying to achieve same requirement in human resource scope so delete members and add members in a particular group is not possible as we are not in global scope.
So we trying to write script include in global scope and catalog client script please guide us
Below I am attaching my script include and client script
Client script:
function onChange(control, oldValue, newValue, isLoading) { if (isLoading || newValue == '') { return; } //Type appropriate comment here, and begin script below var ga = new GlideAjax('removeUsers'); ga.addParam('sysparm_name', 'removeUs'); ga.addParam('sysparm_groupname', g_form.getValue('group_name')); ga.addParam('sysparm_groupusers', g_form.getValue('remove_members')); ga.getXML(checkRes); function checkRes(response) { var answer = response.responseXML.documentElement.getAttribute("answer"); alert(answer); } }
Script include:
var removeUsers = Class.create(); removeUsers.prototype = { removeUs: function() { var groupName = this.getParameter('sysparm_groupname'); var users = this.getParameter('sysparm_groupusers'); var gr = new GlideRecord('sys_user_grmember'); gr.addQuery('sys_id', groupName); gr.addQuery('sys_id', 'IN', users); gr.query(); gr.deleteMultiple(); return 'success'; }, type: 'removeUsers' };