How to delete trigger from script ?

Hi,

Question:
How to delete trigger from script ?

Script below “hangs” TDM.

function BtTriggersDELOnClick ()
{
var Log = System.CreateObject(‘Log’);
var Model = Entity.Root();
/*
We need to read original object. ‘Entity’ is only a temporary
object (created when a form is edited) that that doesn’t have
all properties loaded/filled.
*/
var OrigEntity = Model.Entities.GetObjectById( Entity.Id );

Log.Information (“Button DEL TRG - START”);
Log.Information(OrigEntity.Name);
// Triggers
for (t=0; t<OrigEntity.Triggers.Count; t++)
{
Trigger = OrigEntity.Triggers.GetObject(t);
Trigger.Delete();
}
Log.Information (“Button DEL TRG - END”);
}

for (t=0; t<OrigEntity.Triggers.Count; t++)
{
Trigger = OrigEntity.Triggers.GetObject( t );
Trigger.Delete();
}

If you want to delete all triggers in entity, the easiest script modification would be this:

var TriggerCount = OrigEntity.Triggers.Count;
for (t=0; t<TriggerCount; t++)
{
Trigger = OrigEntity.Triggers.GetObject( 0 );
Trigger.Delete();
}

If you have any questions, please write us back. Thanks.

Regards,

Vladka + Mario

Hello,

Deleting triggers changes their number. So, you cannot use:
Message was edited by: vladka

Hello Vladka + Mario,

Thank You for Your answer.
I used Your code and … It hangs again :-(((

Best regards,

Adam

FYI:
Toad Data Modeler:

  • File Version: 3.3.7.22
  • Licence Number: XXX-XXXXX
  • Licence Type: Permanent
    Remaining Days: n/a
    Expires On: n/a

Model:
Database: Db2 v.9 (LUW)

BtTriggersDELOnClick()

to:

BtTriggersDELOnClickSilent()

Now it should work. Thanks!

Regards,

Vladka + Mario

Hi Adam,

Oops! You’re right.

It’s necessary to run the function in Silent Event, so please rename this function:

Hi Vladka + Mario,

It works.

Thank You very much.

Best regards,

Adam

Great!

Vladka + Mario