6 Replies Latest reply on Feb 25, 2012 4:05 AM by roberttaylor66

    OnLayoutExit Trigger, what is the expected behavior?

    roberttaylor66

      I am using FM Pro Advanced 11 v3 on Vista.

       

      I am trying to leverage the OnLayoutExit trigger to clear some global variables when a layout closes.

       

      Per the documentation, I am expecting this trigger to fire when a layout is exited (closed).

       

      However, I am discovering that sometimes the trigger fires when another layout is being opened.

       

      In particular, this happens when the subject layout (the one with the OnLayoutExit trigger) has focus and a custom menu item is used to open a new layout.

       

      I've attached a file that demonstrates this problem.

       

      I think this is a bug, but I am fairly new to FM so I'm not sure if this behavior is expected.

       

      Can someone run my example and confirm that this is indeed unexpected behavior?

       

      Thanks.

        • 1. Re: OnLayoutExit Trigger, what is the expected behavior?
          PalmDBS

          When you create a new window, it opens with the sme layout as the current window.  When you subsequently change the layout in the new window, it IS exiting the layout and triggering the OnLayoutExit. 

           

          One solution is to use a global field to indicate that you are running the opener script, checking that value in your OnLayoutExit trigger (and exiting if the global indicates you are in the Open Layout scripti), then changng the global back. 

           

          Something like

           

          New Window.....

          Set Field [Global::OpenLayoutScriptRunning;1]

          Go to Layout.....

          Set Field [Global::OpenLayoutScriptRunning;0]

           

          Then, in your OnLayoutExit script, add at the top

          If [Global::OpenLayoutScriptRunning=1]

          Exit Script          (edited per comment below)  

          End If

           

          I'm sure there are other solutions out there, that's just what comes to mind off the top of my head - I'm still very new to FM.

           

          Mike

          • 2. Re: OnLayoutExit Trigger, what is the expected behavior?
            Malcolm

            Definitely not a bug.

             

            Try this:

            1. With Layout 2 open, open layout 1 via script in scripts menu. The trigger is fired.

            2. With layout 2 open, open layout 2 via script in scripts menu. The trigger is not fired.

             

            What this reveals is that the trigger is coming from the newly opened window. When you create a new window it opens in the current layout. When you go to layout 1 you are exiting layout 2 from the new window. The onLayoutExit script is triggered.  In the second case you open a new window but you don't exit layout 2 so the script is not triggered.

             

            You must be extremely careful with the application of layout level script triggers. Especially when you add them retrospectively because they cannot be suppressed. There is no way to say "exit layout 2 ignoring script triggers".  You will have to rewrite your scripts to manage the new behaviour. For example

             

                    1. layout triggered script

            if

                 exit script[]

            else

                show custom dialog ["boo hoo"]

            end if 

             

                    1. script which will may trigger layout level scripts

            set variable

            set variable

            set variable

            go to layout

            set variable [ $$suppressOnRecordCommit ; ""]

            set variable [ $$suppressOnLayoutExit ; "" ]

            set variable [ $$suppressOnLayoutEnter ; ""]

             

            If you use this method I suggest that you name the variables for the exact behaviour to control. This is advisable because you may have other scripts triggered at different levels. An important point about the triggers is that multiple events will be triggered so it is possible to have many actions occurring by a single script step. A single "go to layout" command will pass at least four triggers and each can invoke a script.

             

            Malcolm

            • 3. Re: OnLayoutExit Trigger, what is the expected behavior?
              Malcolm

              On 25/02/2012, at 3:24 PM, dbmike:

              Then, in your OnLayoutExit script, add at the top

               

              If Global::OpenLayoutScriptRunning=1

               

              Halt Script

               

              End If

               

               

              Don't do that. HALT is for use when you want to halt everything. You simply want to exit the current script.

               

              Malcolm

              1 of 1 people found this helpful
              • 4. Re: OnLayoutExit Trigger, what is the expected behavior?
                PalmDBS

                D'oh... sorry about that!  Typed in the wrong one.  Thanks for pointing it out!

                • 5. Re: OnLayoutExit Trigger, what is the expected behavior?
                  comment

                  roberttaylor66 wrote:

                  Per the documentation, I am expecting this trigger to fire when a layout is exited (closed).

                   

                  A layout is not a window: it cannot be closed. Going to another layout (in the same window) exits the current layout.

                  • 6. Re: OnLayoutExit Trigger, what is the expected behavior?
                    roberttaylor66

                    Thanks everyone.

                     

                    I now understand completely.