- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-25-2022 01:11 AM
1: When a new user is added to ServiceNow, check their division is "A" and add them to the group "G".
2: When a user is made inactive, check their division is "A" and remove them from the group "G".
Solved! Go to Solution.
- Labels:
-
Customer Service Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-25-2022 01:16 AM
Hi,
should be simple enough.
Is division a field on User table which will be populated during insertion?
if yes then use this
1: When a new user is added to ServiceNow, check their division is "A" and add them to the group "G".
-> After insert BR on sys_user table
Condition: Division == 'A'
Script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var rec = new GlideRecord('sys_user_grmember');
rec.initialize();
rec.user = current.sys_id;
rec.group = 'groupA SysId';
rec.insert();
})(current, previous);
2: When a user is made inactive, check their division is "A" and remove them from the group "G".
-> After update BR on sys_user table
Condition: Active = False && Division == 'A'
Script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var rec = new GlideRecord('sys_user_grmember');
rec.addQuery("group", 'groupA SysId');
rec.addQuery("user", current.sys_id);
rec.query();
if(rec.next()){
rec.deleteRecord();
}
})(current, previous);
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-13-2022 06:35 AM
Thanks a Lot Ankur, It helped me. Marking your answer as correct
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-26-2025 06:23 AM
Hi @Ankur Bawiskar ,
Need help in one scenario.
In my Account User getting created and adding into Group 'X'.
The requirement is Based on user group membership need to populated value in Business Unit and BU column.
Note: Both BU and Group details we are pulling it from sys_user_group table only.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-26-2025 06:26 AM
can you post a new question for this and tag me there?
share complete business requirement and screenshots and also what script did you try so far and what debugging did you perform?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-25-2022 01:18 AM
Hi,
You can achieve this with the help of After Business rule on sys_user table.
once a record is inserted check the division and then Glide in the sys_user_group table and add the user there in its member.