2 Replies Latest reply on Jun 26, 2014 4:56 PM by KyleCarroll

    Stopping a running script, with a script.



      Stopping a running script, with a script.


           In my database, I have a button labeled "Insert Image" which, when clicked, will run a script which will make a container field active, and bring up the insert picture window. Also, the container contains a Script Trigger, which when the container is active, will run a script that will open the image in the computer's photo browser.

           My issue is that, since the script trigger happens when the field is active, every time I use the "Insert Image" script, it also runs the "Enlarge Image" script.

           Is there anyway to prevent the script from running, if a specified script is already running? For example, in my "Enlarge Image" script, I would like it to say "If InsertImage Script is Running, Exit Script, Else, Enlarge Image". Is this sort of command possible?

        • 1. Re: Stopping a running script, with a script.

               FileMaker can only perform one script at a time. When a script trips a script trigger set to perform a script, the current script is paused and the trigger performed script then runs. Control eventually returns to the paused script and it continues  from the point where it was paused unless a Halt script step is performed--at which point all paused scripts are terminated. (That's why there is both a halt script and an exit script step.)

               Not only can this create situations where one script performs another script that you do not want performed, but scripts can even trip their own script trigger and thus trap you in an infinite loop.

               To keep trigger performed scripts from executing when I don't want them to even though a script may have tripped the trigger, I enclose all trigger performed scripts in an identical If block:

               IF [ Not $$TriggersOff ]

               Rest of script goes here

               End IF

               Then, any time that I need to disable triggered scripts, I just set the global variable to True.

               Thus your insert Image script might have these steps:

               Set Variable [$$TriggersOff ; Value: True ]

               Rest of script goes here

               Set Variable [$$TriggersOff ; Value; False ]

               The key detail is to always reset the variable to false or your script will leave your database in a state where none of the triggered scripts will run.

          • 2. Re: Stopping a running script, with a script.

                 Wow. That worked perfectly. It was almost too easy! Thanks!