- 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
‎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
‎08-25-2022 03:10 AM
Hi Ankur,
Will try with the following and let you know.
Thanks in advance,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-25-2022 03:27 AM
Thank you for marking my response as helpful.
If my response helped please mark it correct and close the thread so that it benefits future readers.
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
‎08-30-2022 09:57 AM
Hope you are doing good.
Did my reply answer your question?
If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader