Delete multiple records from 'sys_user_grmember'

Vijay Baokar
Kilo Sage

Hi Folks,

 

I am trying to delete record from "sys_user_grmember" table if user is not active but still part of active group. Below is the scheduled job i am trying with but its taking time to remove the records form "sys_user_grmember" table however this table has 600 records.

 

 var groupMemberGR = new GlideRecord('sys_user_grmember');
    groupMemberGR.addEncodedQuery('user.active=false^group.active=true^user.u_employee_status=c1d616dc0f136100031a5d78a1050ea7');
    groupMemberGR.query();

    // Remove the user from all groups they belong to
    while (groupMemberGR.next()) {
       
        // Delete the group membership record
        groupMemberGR.deleteRecord();
        //groupMemberGR.deleteMultiple();
    }
 
how can we make it for quick clean up of records?
3 REPLIES 3

Ravi Chandra_K
Kilo Patron
Kilo Patron

Hello @Vijay Baokar 

Is this one time activity?

If yes, the same script can be executed via Fix script where you can see progress workers and know the status.

This will take around same time even if you do it manually from front end.

Please mark this answer as helpful and correct if helped 

Kind Regards,

Ravi Chandra.

Hi @Ravi Chandra_K What if we want to run the same script during weekend for cleanup data? Just to make sure we don't have irrelevant data in the system.

But parallelly we have a BR as well which will run whenever user is moved from active True to active false then the same thing we are doing in BR as well, deleing records from sys_user_grmember.

Ravi Chandra_K
Kilo Patron
Kilo Patron

If it's regular cleanup data, then scheduled job. Much better if it's weekend for better system performance. On the amount of time for this activity, I  don't think there's any way for quick cleanup as it takes the same amount of time to delete the records from database. (either from any script or manual activity).

 

Please mark this answer as helpful and correct if helped. This helps both community and me 

Kind Regards,

Ravi Chandra