cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Java - deletion of obsolete users

simikadampatta
Trusted Contributor

Hi Community,

I have a Java-based batch job which deletes obsolete users. There is a Boolean MetaAttribute 'To be deleted'. If that is checked for a Person (System) object, that object is deleted. But when that job runs, all users with 'To be deleted' MetaAttribute checked are not deleted. On running the job again, some of the remaining users are deleted. I am not sure why all the users fullfilling that condition are not deleted at one-go. Please find code snippet below:

 MegaCollection CollPersonSystem = root.getSelection("Select [Person (System)] Where [To be Deleted] = 1");
appLogger.info("Triggering the Clean Up task ");
for (MegaObject ObjPersonSystem : CollPersonSystem) {
appLogger.info("(Maintainence Activity) Deleting the person system." + ObjPersonSystem.getProp("Name"));
ObjPersonSystem.delete("");
}
MegaCollection CollLogin = root.getSelection("Select [login] Where [To be Deleted] = 1");
for (MegaObject ObjlLogin : CollLogin) {
appLogger.info("(Maintainence Activity) Deleting the Login." + ObjlLogin.getProp("Name"));
ObjlLogin.delete("");
}
appLogger.info("End the Clean Up task "); 

 

3 Replies

MAngouch
MEGA
MEGA

Hello,

You can just call the following operator to delete the collection:

CollPersonSystem.callMethod("~bHnwJiVr3vZ0[QueryDelete]","SilentMode,NoCheckDeletable","");

Thank you for your help!

oguimard
Retired

Hello,

You algorithm is not good. 

In fact when you delete an item in a collection "the pointer" is moved to the next element. Your current script will only delete "half" of the element of the collection. Thus the behavior your are describing. 

Instead of "For" you should do a "While".

While CollPersonSystem .count > 0 Do

CollPersonSystem .item(1).delete

End