8 Replies Latest reply on Nov 4, 2016 10:32 PM by laguna92651

    Conditionally Disable OnLayoutEnter Script

    laguna92651

      I have a button on records in list view, that opens a new window for that record. The script that opens the new window is sluggish. This script only consists of:

       

      Set Field

      New Window

      Go To Layout

      Sort

       

      When I run the script debugger and run the call "new window script", I noticed that a find script that I use on the OnLayoutEnter trigger runs, on the base layout, is causing the delay and flicker. I wouldn't think this should run, but if it should run, is there a way to only run the OnLayoutEnter find script when I actually enter the base layout, not run the OnLayoutEnter script when I click the new window button?

        • 1. Re: Conditionally Disable OnLayoutEnter Script
          coherentkris

          wrap the steps of the script that fires onLayoutEnter in an if statement that checks for a value in a global variable.

           

          if ( $$FireTriggers = True ) then

          <<insert script body here

          end if

           

          all you have to do is set the global to anything but 1 to prevent the actions of the script.

          The trigger will still fire and the script will run but it wont do anything.

          As a practice i wrap all scripts that are fired by triggers with a similar construct

          Use a global so you can change the value while debugging

          • 2. Re: Conditionally Disable OnLayoutEnter Script
            laguna92651

            Do I have to set the $$TriggerFire to True when I exit the layout? Is that normal behavior for the OnLayoutEnter to run, when I run the script from the record?

            • 3. Re: Conditionally Disable OnLayoutEnter Script
              philmodjunk

              I would turn the logic of this around.

               

              At the start of your ONLayoutEnter trigger performed scirpt, write it this way:

               

              If [ $$TriggersOff ]

                Exit Script []

              End IF

              #Put original script steps here

               

              Then, in your script that opens the new window, do it this way:

              Set Variable [$$TriggersOff ; value: True ]

              New Window

               

              And at some point before this script exits, put in:

              Set Variable [$$TriggersOff ; value : "" ]

               

              This leaves your trigger enabled as your default state and you only need create/define that variable when you need to disable a script trigger. I start all my trigger performed scripts with these steps so I have the option to disable them from another script at need.

              1 of 1 people found this helpful
              • 4. Re: Conditionally Disable OnLayoutEnter Script
                laguna92651

                Thanks, that worked great. I am still curious, should the OnLayoutEnter trigger even be run when I click on a button that is on a record line?

                • 5. Re: Conditionally Disable OnLayoutEnter Script
                  philmodjunk

                  It is normal behavior for New Window to trip both OnLayoutEnter and OnRecordLoad on your current layout. That's because you are entering a layout and loading a record in that new window. It just happens to be the same layout that you already have entered and loaded a record in the first window until you also change layouts in that new window.

                   

                  One way around this that can sometimes be used it to use Go TO Related records to both open a new window and also specify a layout for that new window.

                  • 6. Re: Conditionally Disable OnLayoutEnter Script
                    laguna92651

                    Okay thanks, just wanted to be sure it was normal behavior and I didn't mess something up.

                     

                    One last question, what is the advantage of using a global variable over a global field, its seems I read somewhere that you shouldn't use too many global fields. It also seems like they start to clutter up the script debugger. Thanks

                    • 7. Re: Conditionally Disable OnLayoutEnter Script
                      philmodjunk

                      Much of the time either a global field or a variable may be used. There are differences:

                      A) a global field can be placed on a layout and directly edited by a user. A global variable cannot.

                      B) a global field can be used as a match field in a relationship. A global variable cannot.

                      C) A global variable does not exist in your relationship until it is created by set variable or the let function gives it a value. It persists until the file is closed or it is set to an empty string.

                      D) References to variables are faster than field references.

                      • 8. Re: Conditionally Disable OnLayoutEnter Script
                        laguna92651

                        Thanks for the help, I appreciate it.