6 Replies Latest reply on Apr 13, 2012 4:59 PM by philmodjunk

    Trigger Traps


      Trigger Traps


      Since there are discussions about slowness in list view I thought I might list a problem I created for myself. 

      Using a layout trigger I selected one that did a lot of work and delayed the initial listing by just a bit. I applied to to on layout load. For some reason I then applied to on record load and my list speed disappeared. After a bit of debugging work, I realized what I had done. My monster trigger was just fine when the layout loaded but was a dog when each record loaded. So, removed the on record load trigger and everything returned to normal speed.

      When I use a layout to create a new record or loop through a lot of records to update them, I freeze the window and use a table with no triggers and very few fields and none of them calculating if possible. AND NO TRIGGERS. This Table Lite speeds things up. When done I then go to a different layout or the original one.

      Using a trigger-free table can also help with a find or a sort.

        • 1. Re: Trigger Traps

          I've done a "face plant" or two due to layout based script triggers kicking in and interferring with scripts that change layouts or records....

          A trigger free stripped down layout is a good option and I use it, but I also use a second method as well: I use a global variable to "turn off" my layout based script triggers.

          I write scripts performed by such triggers like this:

          If [ Not $$TriggersOff ]

            #Put rest of script here

          End If

          Then, any scripts that might trip such triggers set $$TriggersOff to True before they change layouts, etc and then set the value back to false at the end of the same script.

          • 2. Re: Trigger Traps

            PhilModJunk, I swear you must be stalking me since your posts sound just like stuff I used to do. Did someone give you copies of my solutions? 



            • 3. Re: Trigger Traps

              Hmm, the script could be even expanded:

              IF($$_trigger_state = true)


              Else IF ( $$_trigger_state = false)


              Else IF ( $$_trigger_state = "Maybe")




              End If

              I may change my triggers to use patterncount(get(layoutname); "Table" ) > 0 and so on since I typcially name my layouts TABLE tablename and FORM tablename and LIST tablename.

              So much to do, so little time...

              • 4. Re: Trigger Traps

                Please note that sometimes changing to a trigger free layout does not work as the triggered script  that interferes is set on the layout from which you must perform your script. Consider the case where you have an OnRecordLoad trigger on the layout where you click a button to perform a script that changes layouts, does its stuff and then returns to the original layout. That last step, where you return to the original layout will trip the trigger and you can't avoid tripping it because it's part of your original layout and you have to come back to it.

                For that reason, I shared an alternative approach that you can use in such cases.

                • 5. Re: Trigger Traps

                  Good point.

                  An added idea to yours:

                  use the trigger to set a variable to indicate that the trigger has done its work...then the first time the layout shows, it works but not on sucessive loads. 

                  IF 1, it has been run

                  IF 0, OK to continue (see your post)

                  IF 0

                  xxxx stuff

                  set var to 1

                  else if 1


                  end if

                  Your script sets var to 0 before going to layout. Navigation buttons also set var to 0.

                  Var could also be set to different values with different IF steps for each.

                  Interesting and I am sure it will drive me nuts...!

                  • 6. Re: Trigger Traps

                    Yep, been there done that too.

                    And when I first "tripped over triggers" like this, my FIRST idea was the trigger free layout and the $$global variable switch came later...Wink