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

I would go with a scheduled job. Business rule is only going to trigger when the record is created/changed/etc. If you miss that 28 day window, there's no action taken. A scheduled job that runs nightly can help with that.



The question is... where are you tracking the time the record was set to inactive? It's one thing to check the box, but relying on sys_updated_on (date/time field) for your 28 day counter could provide incorrect results.


Thanks chuck, we have one date field to store inactive date of user


This script is working fine chuck lot of thanks for this


Hey @Chuck Tomasi - 

I know this post is old, but I am trying to accomplish something just like this using a scheduled job.

I used this as of right now - which worked, however it removed ALL members from the group. I only want to remove the person based on a custom field 'u_termed_in_workday'.

Are you able to help?

u_termed_in_workday();

function u_termed_in_workday() {

    var gm = new GlideRecord('sys_user_grmember');
    gm.addQuery('u_termed_in_workday', true);
    gm.query();

    while (gm.next()) {
        gm.deleteRecord();
    }
}

Is u_termed_in_workday a field on the sys_user_grmember table or sys_user? If sys_user, try using user.u_termed_in_workday