Question
· Apr 17, 2017

Overide trigger

Hello everyone.

I have some issue with trigger. I have class where I defined 3 triggers (UPDATE, INSERT, DELETE). These triggers are  Foreach = row/object. In my currently task, I need overide this triggers in children class.  is It possible to do it? 

Thank you for your help.

Discussion (4)0
Log in or sign up to continue

Just redefine the trigger with the same name in a child class:

Class FormsDev.NewClass1 Extends %Persistent
{

Property Name As %String;

Trigger Insert [ Event = INSERT ]
{
    Set ^dbg = {Name}
}

/// do ##class(FormsDev.NewClass1).Test()
ClassMethod Test()
{
    Kill ^FormsDev.NewClass1D, ^dbg, ^dbg2
    
    &sql(INSERT INTO FormsDev.NewClass1 (Name) Values ('Alice'))
    &sql(INSERT INTO FormsDev.NewClass2 (Name) Values ('Bob'))
    zw ^dbg, ^dbg2
}

}

and child class:

Class FormsDev.NewClass2 Extends FormsDev.NewClass1
{

Trigger Insert [ Event = INSERT ]
{
    Set ^dbg2 = {Name}
}

}

Test:

>do ##class(FormsDev.NewClass1).Test()
^dbg="Alice"
^dbg2="Bob"

 

Also, if you change trigger name, both would be executed. For example Insert in NewClass1:

Trigger Insert [ Event = INSERT ]
{
    Set ^dbg($i(^dbg)) = {Name}
}

And Insert2 in NewClass2:

Trigger Insert2 [ Event = INSERT ]
{
    Set ^dbg2($i(^dbg2)) = {Name}
}

Would result in:

>do ##class(FormsDev.NewClass1).Test()
^dbg=2
^dbg(1)="Alice"
^dbg(2)="Bob"
^dbg2=1
^dbg2(1)="Bob"