- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2022 12:42 AM
1. I have created one catalog item "Add Remove client portal Admnistrators".
2.On this catalog item added two variables:
1.Contact to Add - When the User move in Selected, Automatically add to the 'Client portal group'
2.Contact to Remove - When User move in Available,Automatically remove from the 'Client portal group'.
3.My requirement is adding or removing users from the 'Client portal group'. I want to implement this using workflow.
Thank You.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2022 03:35 AM
Hi,
try this
var usersToAdd = current.variables.contact_to_add.toString().split(','); // give correct variable name here
var usersToRemove = current.variables.contact_to_remove.toString(); // give correct variable name here
var rec = new GlideRecord('sys_user_grmember');
rec.addQuery("group.name", "Client portal group");
rec.addQuery("user", 'IN', usersToRemove);
rec.query();
while(rec.next())
rec.deleteRecord();
for(var i in usersToAdd){
var rec1 = new GlideRecord('sys_user_grmember');
rec1.addQuery("user", usersToAdd[i]);
rec1.addQuery("group.name", "Client portal group");
rec1.query();
if(!rec1.hasNext()){
rec1.initialize();
rec1.user = usersToAdd[i];
rec1.setDisplayValue('group', "Client portal group");
rec1.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
09-05-2022 12:45 AM
Hello,
These threads have code, please tweak accordingly
https://community.servicenow.com/community?id=community_question&sys_id=9dcb3e211bde0d109337ece6b04bcb17
https://community.servicenow.com/community?id=community_question&sys_id=aba38f65dbd8dbc01dcaf3231f9619e4
https://community.servicenow.com/community?id=community_question&sys_id=e69161d61bcc309017d162c4bd4bcbf1
Please hit like and mark my response as correct if that helps
Regards
Regards,
Musab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2022 12:55 AM
Hi,
should be an easy script
Sharing sample workflow run script; please enhance it
var usersToAdd = current.variables.variableA.toString().split(','); // give correct variable name here
var usersToRemove = current.variables.variableB; // give correct variable name here
var rec = new GlideRecord('sys_user_grmember');
rec.addQuery("group.name", 'Client portal group');
rec.addQuery("user", 'IN', usersToRemove);
rec.query();
while(rec.next())
rec.deleteRecord();
for(var i in usersToAdd){
var rec1 = new GlideRecord('sys_user_grmember');
rec1.addQuery("user", usersToAdd[i]);
rec1.addQuery("group.name", "Client portal group");
rec1.query();
if(!rec1.hasNext()){
rec1.initialize();
rec1.user = usersToAdd[i];
rec1.setDisplayValue('group', "Client portal group");
rec1.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
09-05-2022 01:58 AM
Hello
Your scrips works perfectly, Thank You.
1.I can add Group Member sucessfully in the Group "Client portal group".
2. But when I removed the Group Members from the 2nd Variable i.e. variableB ,there is still empty record is present in Group Members related list.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2022 02:05 AM
Hi,
the logic is correct.
can you share the script here?
which user is that one which shows empty?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader