A couple of things here.
1) After setting the where clause, you should call a reset (IE emailset.reset())
2) You can bulk delete by utilizing emailset.deleteAll(). This avoids looping through the records to delete if you're not executing any additional logic.
3) Don't save a set more than once. In your example you're saving after each record.
I'd write this more like:
from psdi.server import MXServer
mxServer=MXServer.getMXServer()
userInfo=mxServer.getSystemUserInfo()
emailset=mxServer.getMboSet("EMAIL",userInfo);
emailset.setWhere("PERSONID like 'GT%'")
emailset.reset()
emailset.deleteAll()
emailset.save()
emailset.close()
------------------------------
Steven Shull
Projetech Inc.
------------------------------
Original Message:
Sent: 05-18-2021 09:54
From: Harshavardhan Kamepalli
Subject: Delete certain records from E-Mail table with Automation Script
Hi,
I have a requirement to delete records from E-Mail table for users starting with certain prefix like 'GT'.
I have written the following script but it doesn't seem to work. Could anyone help me in finding the mistake in the following script.
from psdi.server import MXServerimport sysmxServer=MXServer.getMXServer()userInfo=mxServer.getSystemUserInfo()emailset=mxServer.getMboSet("EMAIL",userInfo);emailset.setWhere("PERSONID like 'GT%'")if (emailset!= None or emailset.isEmpty()==False): G=0 team=emailset.getMbo(G) while(team is not None): team.delete() emailset.save() G = G + 1 team= emailset.getMbo(G)
Is there any other to write the script with SQL Query to achieve the requirement?
#Customizations
------------------------------
Harshavardhan Kamepalli
Eidiko System Integrators
------------------------------