‎27-04-2023 01:28 PM
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 ");
Solved! Go to Solution.
‎27-04-2023 10:12 PM - edited ‎27-04-2023 10:22 PM
Hello,
You can just call the following operator to delete the collection:
CollPersonSystem.callMethod("~bHnwJiVr3vZ0[QueryDelete]","SilentMode,NoCheckDeletable","");
‎27-04-2023 01:57 PM
Thank you for your help!
‎27-04-2023 01:52 PM
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