BR to set user 'active' field to false if member of a certain group

StewartFletcher
Tera Expert

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'

14 REPLIES 14

@StewartFletcher 

Glad to know.

Please mark my response as correct and close the thread.

you need to use before delete BR on sys_user_grmember table and do the reverse

i.e. make the active field as true

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Unfortunately that hasn't worked. Got it set to before delete on the same table, changed the script to set active to true. Hasn't updated though. As mentioned, there is a Locked Out field that ticks when active goes to false, but when you remove the group, active stays false and locked out stays true.

@StewartFletcher 

when user is added you do this -> mark user as active false and locked out as true

when user is removed then you do this -> mark user as active true and set locked out as false

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

There's another BR that is overriding this for locked out. I've disabled it to test, but active checkbox still doesn't go back to true.

Typing it in manually -:

 

(function executeRule(current, previous /*null when async*/) {

    // Add your code here
    var rec = current.user.getRefRecord();
    rec.active = true;
    rec.locked_out = false;
    rec.update();

})(current, previous);
 
Doesn't work.