- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2021 11:24 PM
Hello,
We are looking to set up a automated process to add users to a specific group and remove them dynamically once or twice a day. Group membership criteria would be:
Active = true
Locked Out = False
Employee Type = Internal or External
Email Ends with "sec.com"
If people qualify they are put in the list, if they do not qualify they are removed. What would be the best way to achieve this with a script? Would appreciate if I can get a sample script for this.
Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2021 11:31 PM
Hi Bruce,
something like this
var rec = new GlideRecord('sys_user');
rec.addActiveQuery();
rec.addQuery('locked_out', false);
rec.addQuery('employee_type','IN','external,internal');
rec.query();
while(rec.next()){
if(rec.email.toString().endsWith('sec.com')){
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', rec.sys_id);
gr.addQuery('group.name', 'Group ABC');
gr.query();
if(!gr.next()){
gr.initialize();
gr.user = rec.sys_id;
gr.group.setDisplayValue('Group ABC');
gr.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
05-12-2021 11:30 PM
Hi,
Will there be any catalog item to automate this wherein users will raise request for adding/removing users to/from group
If yes then you can have catalog item designed for this and use workflow run script to add/remove users
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
05-13-2021 06:51 AM
This is not for a catalog it. Just a group created to add to dashboard so users in it can view the dashboard. Any suggestion on how to achieve the use case?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2021 07:34 AM
Hi,
then how it would be happening as dynamic unless you setup some process around this scenario
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
05-13-2021 07:43 AM
What do you think the best approach would be in this case? Just looking for a way to auto assign active users that meet the criteria into the group. When active changes to false, then if they can be removed from group.