Topic
  • 2 replies
  • Latest Post - ‏2019-08-19T21:56:03Z by llandale
Juanfergar
Juanfergar
21 Posts

Pinned topic Disable/enable trigger

‏2019-07-02T06:53:22Z | trigger

Hi,

 

I want to know if exists some function to disabled a trigger during the execution of my script and then other function to enable it.

 

I have a script that make some changes and I have a trigger that start with one of those changes. I'd like that doesn't execute the trigger if the change is with my script, so I was thinking in disabled the trigger in the begining of my script and enable it at the end of the script.

 

it is possible?

 

Thank you!

  • Mike.Scharnow
    Mike.Scharnow
    586 Posts

    Re: Disable/enable trigger

    ‏2019-07-02T08:05:50Z  

    See https://www.ibm.com/developerworks/community/forums/html/topic?id=efff3796-f46f-4e8d-b2ee-b7cb73772df1 for a discussion and some possible workarounds/solutions. 

    Have a look especially at the last comment which recommends rethinking your trigger strategy.

  • llandale
    llandale
    3088 Posts

    Re: Disable/enable trigger

    ‏2019-08-19T21:56:03Z  

    I do see "enable(Trigger)" and "disable(Trigger)" DXL perms, but have never seen them before.  I'm guessing they only work on Dynamic triggers.  In any event it would be difficult to write a DXL to disable specific triggers.

    bool State = getTriggerState_()  // This returns the state of the flag; not whether it works.  Even when this returns false, triggers still run for non-DB admins.
    setTriggerState(bool)   // false is same as using -T command line switch; but you can turn running triggers back on.
     

    In your case, however, I think the Trigger code needs to be clever and know when to do nothing when invoked.  Here are some possibilities:
    o When the module is invisible|
    o when inplaceEditing(Module) return false
    o when (getTriggerState_() == false)

    If we presume you did that last one, your on-demand script can do this:

    bool StatePrev = getTriggerState()

    setTriggerState(false)

    make your updates

    setTriggerState(StatePrev)

    -Louie