1answers

A Global does the trick

I have been watching some training on FileMaker, and currently the instructor is showing how to build a system that navigates the Layouts in a solution. In the early stage of it, we have only added the back button.

An interesting thing has come up, and I figured I am better off trying to fully understand what is going on rather than just be satisfied I can get it working in my solution.

For the back button we built one Script that get attached to the Layout via a Trigger (it stores a variable that is list of Layout numbers) and one that gets attached to the button (It retrieve the Layout we want to return to and removes it from list).

The instructor then explained why it wouldn't work (seems like it should). He says that the other scripts firing on the Layout will clash with it so it cannot do its job. He goes on to show a procedure that fixes the problem. I present it in the pictures, I think what is going on here is it is he is creating a clause that will say “no matter what, create a situation for this to run” but that is just what I see.

What does this $$Nav global variable (pic) do for you that makes it work (it does work)?

Chris Johnston

Answers

The $$Nav variable in the screenshots you're showing does something similar to the custom functions that support the suppressible triggered scripts best practice.

Think about what happens without the $$Nav variable. Let's suppose the $$Back variable contains the values 3¶2¶1 at the beginning. When you run the button script ("Back Navigate"), the script will go to layout 3 (the first value from the $$Back variable). Immediately upon entering layout 3, the script trigger will run the "Back" script, interrupting (but not canceling) the execution of the button script. The trigger script adds the current layout to the $$Back variable, which will now be 3¶3¶2¶1. When the button script resumes, it removes only the first value from $$Back, setting it to 3¶2¶1 again. The trigger added the layout to $$Back right before the button script had the opportunity to remove it, so $$Back is ultimately unchanged.

What you want to happen is for the OnLayoutEnter script trigger to add the layout to $$Back, unless you got there by calling the "Back Navigate" script. Setting the $$Nav variable signals the "Back" triggered script that we just entered the layout by the action of the "Back Navigate" script, so that the "Back" script knows not to do it's usual operation, giving the "Back Navigate" script the opportunity to remove the layout from $$Back correctly.

This sort of thing is a routine complication with using script triggers. The custom functions I linked to above are generally a more robust way to deal with this sort of thing than managing the global variable yourself. Using those, your scripts might instead be something like this:

# Back Navigate

If [IsEmpty ( $$Back )]

Show Custom Dialog [...]

Else

Set Variable [$!; Value:TriggersDisable]

Go to Layout [...]

Set Variable [$!; Value:TriggersEnable]

Set Variable [$$Back; Value:...]

End If

# Back OnLayoutEnter

If [TriggersAreActive]

Set Variable [$$Back; Value:...]

End If

Jeremy Bante

Great answer! Thank you a lot. You describe its logic so well, that is also a great site you linked me to for the FileMaker Standards. Man the FileMaker resources Great Forums(Like this one) and people like your self have made leaning FileMaker great!

Back to questions