BR to set user 'active' field to false if member of a certain group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2023 02:30 AM
We are looking to try and set users 'active' field to false if they are part of a certain group.
However, it appears the sys_user table cannot see the Groups related list, meaning I think we'd have to script that somehow.
Done a lot of scouring and cannot see anything that points to a solution. I see things about checking if a user is in a group, but not then 'do this'. I'm very much a scripting novice
So essentially if user is member of 'test group', then set Active to 'false'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2023 02:51 AM
are you saying when user is added to particular group you want that user to be marked active false?
if yes then you will require after insert business rule on sys_user_grmember table
You need to be cautious since that user might be present in assigned to of tickets in your instance. If there won't be any tickets/cases assigned to those users then you are good.
Condition: Group [IS] Group ABC
Script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var rec = current.user.getRefRecord();
rec.active = false;
rec.update();
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2023 03:00 AM
Hi Ankur - this is 100% likely me not being clued up with scripting, but this doesn't seem to like that.
Does the condition need to be code too?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2023 03:07 AM
give that in the filter condition field
you can directly select Group [IS] <select the group>
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2023 03:31 AM
That's worked perfectly, thank you.
Next thing I've just been asked - to reverse it, if we remove the user from the group, they stay as active = false. We want to change that to true - but creating another script to set that when the group changes from our 'test deactivate user' doesn't work. We have a Locked Out field that also sets, but seems we cannot reference that? Any thoughts