schedule job to reomve inactive users from group .

raghuv
Giga Contributor

I want to create schedule job to remove inactive users from group

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

Hi Raghu,



How about something like this... Note this is not tested... Always backup your data (e.g. export the sys_user_grmember table to XML) before testing with the deleteRecord operation.



(function () {


var gm = new GlideRecord('sys_user_grmember');


gm.addQuery('user.active', false);


gm.query();


while (gm.next()) {


        gm.deleteRecord();


}


})();


View solution in original post

18 REPLIES 18

Chuck Tomasi
Tera Patron

Hi Raghu,



How about something like this... Note this is not tested... Always backup your data (e.g. export the sys_user_grmember table to XML) before testing with the deleteRecord operation.



(function () {


var gm = new GlideRecord('sys_user_grmember');


gm.addQuery('user.active', false);


gm.query();


while (gm.next()) {


        gm.deleteRecord();


}


})();


Thanks Chuk



                                          I will test this code and once I done I will let you know.


Hi Raghu,


Adding to Chuck's response and script which should perform the functionality you require, you should also consider adding an on 'after' business rule on the sys_user table to remove the user that's just been inactivated from any groups.


This will ensure that the data is kept up to date moving forward and not only when you run the (retrospective) schedule job.



Thanks,


Robbie


Excellent point Robbie. I just made that recommendation to someone else yesterday. How soon I forget... getting old I guess.