7 Replies Latest reply on Sep 9, 2016 9:52 AM by DavidJondreau

    Can Script Triggers be Disabled From within a Script?

    iking42

      The addition of "Script Triggers" was on the surface, a great thing but it's use  comes with many unexpected pit falls. These could be easly avoided if we could disable script triggers from within a script in a manner similar to the error capture command. The capability already exist since I can disable script triggers in the debug mode. Is this currently possible and my dumb ass coder (me)  hasn't found the correct command?

        • 1. Re: Can Script Triggers be Disabled From within a Script?
          David Moyer

          Hi,

          I'm a dumb-ass, so maybe I can help.  I don't think you can disable triggers from within a script - I'm on FM14.  I found this topic in FM help:

          Changing object data without activating script triggers

          But I don't think it's what you're looking for.

          That is, I don't think FM sends anything (like a "Get"-able function.) that you can use to prevent a trigger from firing.

          I'd like to be proven wrong.

          1 of 1 people found this helpful
          • 2. Re: Can Script Triggers be Disabled From within a Script?
            G T

            Look here.

            Suppressible Triggered Scripts - Best Practices - FileMaker Coding Standards

             

            It uses several custom functions to manage global variables. It cannot prevent a script from firing, but it can prevent any steps within an If statement from being run.

             

            ---

            <quoted from above link>

            Script Patterns

            Any script written to be called by a trigger should begin with an If [] script step checking whether or not script triggers are currently being suppressed (after any header comments) using the TriggersAreActive custom function. That If [] statement should contain all other steps within the script, so that, in effect, the script does nothing while triggers are suppressed.

             

            If [ TriggersAreActive ]

             

                # The rest of the triggered script goes here...

            End If

            Any script that may be disrupted by setting off script triggers can use Set Variable [] script steps to invoke the TriggersDisable and TriggersEnable custom functions as needed. These two functions should always be used in pairs.

             

            Set Variable [ $ignoreMe ; TriggersDisable ]

             

            # Perform operations without complications from triggered scripts...

            Set Variable [ $ignoreMe ; TriggersEnable ]

             

            ---

             

            HTH,

            Greg

            2 of 2 people found this helpful
            • 3. Re: Can Script Triggers be Disabled From within a Script?
              iking42

              Thanks Greg

              Not what I was wishing for but at least do-able. In effect, scripting a local version of ScriptTriggers (On/Off) using a global variable. That will do for now.

              • 4. Re: Can Script Triggers be Disabled From within a Script?
                greatgrey

                What's wrong with?

                If flag = false

                  Exit Script

                end if

                No need to put the rest of script inside the IF.

                1 of 1 people found this helpful
                • 5. Re: Can Script Triggers be Disabled From within a Script?
                  iking42

                  True and also functional but not as obvious to "dumb asses" like my self. Moving the desired script steps inside the IF makes remembering easier for me. Three years from now, I will have forgotten all this and what the short IF statement was all about. Just my mind set I guess. However, your approach is much easier to copy and past into existing script that are destine to be the focus of trigger actions. Thanks for the assist.

                  Ike

                  • 6. Re: Can Script Triggers be Disabled From within a Script?
                    philmodjunk

                    I don't quite see the need for a custom function.

                     

                    I routinely just set the same global variable to True from the script that needs to disable triggers and then set up all my trigger performed scripts to check the value of that one variable before doing anything else.

                     

                    Note that is is a global variable so it uses two dollar signs where the "correct answer" here uses only a script variable-- which won't exist outside of the script that assigns a value to it.

                     

                    Works for me anyway...

                    • 7. Re: Can Script Triggers be Disabled From within a Script?
                      DavidJondreau

                      I personally don't use custom functions for this, but I can see some value. Function names have built in error checking, so you won't accidentally use $$ingoreMe instead of $$ignoreMe. And if you want to change the variable name, say from $$triggerOff to $$triggersOff you don't have to edit all your scripts. Not worth it for me, but maybe for others.