It sounds like your script is stuck in a loop.
Your "Go To Layout" script step is causing the Script trigger to run again (even though you're already on that layout, FileMaker still actively goes to that layout again).
So your script is going to layout, then running the script trigger which goes to layout, which triggers the script trigger... etc.
In your script trigger, add something like:
If( $$scriptTriggersOff <> 1 )
In the "do stuff" part, make sure that if you Go To Layout (same layout), set a variable so that the script trigger won't run (and make sure to set the variable back to null (""):
To turn Script Triggers off:
Set Variable [ $$scriptTriggersOff ; 1 ]
To turn Script Triggers on:
Set Variable [ $$scriptTriggersOff ; "" ]
Hope that helps!
1 of 1 people found this helpful
Martha is correct, as evidenced by your first two steps:
1) Open new window and give it a name
2) Go to Layout (that same layout.)
Whenever you open a new window, any OnLayoutEnter triggers will fire. Hence, your triggered script does this:
1) Open new window
1a) Trigger fires
1a.1) Open new window.
1a.1a) Trigger fires.
1a.1a.1) Open new window.
1a.1a.1a) Trigger fires.
1a.1a.1a.1) Open new window.
1a.1a.1a.1a) Trigger fires.
Repeat until force quit or until FileMaker crashes.
Martha's solution will fix the problem.
Very helpful guys - thanks! I should have thought of that!
I'm still not 100% clear on the instructions for the fix, but I'll work on it!!
This is what is on the file you shared:
Enter Browse Mode
If [ $$first_time ] Exit Script [ ]
Set Variable [ $$first_time; Value:1 ]
Go to Layout [ “rpt_weekly” (mnt_renewal_rates) ]
Sort Records [ Keep records in sorted order; Specified Sort Order: mnt_renewal_rates::region; ascending ] [ Restore; No dialog ]
[ Flush cached join results; Flush cached external data ] Set Variable [ $$first_time; Value:"" ]
I know that "$$" is a 'global variable', but with apologies for the dumb question, What is that? What does it do? or What is it doing in this script? (hoping you answer the question I need to ask, because I'm guessing at which question to ask...;))
I need a Find before the Sort, that seems simple enough...
I think the script is saying:
If it's the first time you've run this script then exit the script, If not, then "Set Variable [ $$first_time; Value:1 ] "
I do not know what that means...
Refresh window, that looks like a good thing to do to increase speed of the file??
Again, sorry for the dumb questions...
All good questions!
So a global variable is something that can be set and will "survive" or exist after the script ends. A local variable "$" only lasts until the script ends (and doesn't exist from one script to another).
The first time you enter the layout, the script trigger will trigger.
Enter Browse Mode
Go To layout (same as current layout) - which triggers the script trigger again
So how do you tell the script not to run again? You set a global variable (something that will live outside of the script) as a flag, to tell the script trigger not to actually run again.
On the first time the script trigger runs, set the flag $$first_time to 1.
When the script reaches Go To layout (same as current layout), the script trigger will be triggered. However, now the script trigger sees that $$first_time is set to 1. Based on the If statement, the script will exit and you won't get stuck in an infinite loop.
I think the best way to think of $$first_time is as a flag that stops the script trigger from running over and over again. As long as that flag is turned on, the script trigger will just exit. Once you're done, you turn the flag off, so that the script trigger will properly trigger in the future. It's just a temporary flag to avoid getting stuck in a loop.
Slight correction: Go to Layout will not cause the OnLayoutEnter trigger to fire if the destination layout is the same as the current layout.
Otherwise, good stuff.
Ok, I'm getting that a variable in FM is lot like the clipboard when you copy and paste. If it has 2 $$ it is global, it exists past the current script, until... you use it somewhere? Why the words "first_time"? does FM recognize them to mean the first time you are doing something? first time since when?
1 means Yes?
Honestly I wouldn't blame you if you give up on me, but I sincerely would like to understand it.
No giving up
The global variable exists until you either change the value, clear the value, or close your session.
The name is completely decided by the developer. You could call it $$ScriptTriggerOff or $$DontRunTrigger or $$FirstTime or anything you want. Basically, you're naming a variable whatever you want and then you reference that variable by the same name.
Imagine opening up a file and the opening script sets a global variable ($$startTime) to Get(CurrentTime). Let's say you open it at 9:31am.
At any point during that session (anytime before you close the file), you could run a script that shows the user the value in $$startTime, which would be 9:31am.
Have you used fields set to be global? They can serve a similar purpose. It's a place to store something temporarily.
As for your question about 1 = Yes: It's common for developers to use 1 to mean "yes" or "true" but if you wanted to, you could set the value of the global variable to the word "yes". Basically, you're setting a global variable to some value, and you check for that value in an if statement to run certain script steps based on the scenario.
Huh. For some reason I thought it would run again. Woops! Thanks for the correction!