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
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.
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?
Hmm, the script could be even expanded:
IF($$_trigger_state = true)
Else IF ( $$_trigger_state = false)
Else IF ( $$_trigger_state = "Maybe")
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...
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.
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)
set var to 1
else if 1
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...!