Defensive Layout Navigation
If it hasn’t happened to you yet, then it will at some point. Your FileMaker solution will simply grow and grow and you’ll be adding complex layers of security and access as you develop.
As you add that security, your users may report back that they can’t do what they’re supposed to do. Maybe they’re locked out of a given layout with a giant gray screen with the small words of “No Access”.
Ughhh! What does your user do now? Why should you even be dealing with this issue?
What you really need is to make sure and use defensive scripting strategies where it becomes a small annoyance and you’re both notified and able to investigate why the user is reporting this issue.
In this video, you’ll find a wealth of information about navigating to layouts and how to defensively code against landing on that dreaded “No Access” layout.
Comments
Using layout id
Of course this style guide (to never ever ever ever ever use the layout name) comes at the cost of readability. A price too high if your style guide is to never ever ever ever ever remain layouts. Thoughts?
Marcus
www.humanedevelopment.com
Brittle code is a bad idea.
FileMaker allows for composing code which can easily break. In this regard, it's not encouraging the developer to create robust software. True, reading something like Go To Layout Number 4 is not as easy as Go To Layout Customers, but you have to take reliability over readability in this case.
As I mentioned in the video, which is not necessarily obvious. You can use the go to layout by name (although I would still use the layout by number) and simply create a "layout map" out of global variables.
A startup script would initialize the global variables named to the logical areas of the solution.
$$LAYOUT.CUSTOMERS.FORM = "Customers Form"
$$LAYOUT.CUSTOMER.LIST = "Customer List"
...etc.
At least this way your code is not littered with hard coded literals - which is a bad way to code.
However, you'll be abstracting things even further and making a routine to initialize this on startup where you map layout names to globals.
If that doesn't make sense, then it's a bit too complicated and I would just use the Layout ID & number value along with a comment about which part of the solution it is. Comments within code are always a nice thing for yourself and anyone else.
-- Matt Petrowsky - ISO FileMaker Magazine Editor