Within Claris/FileMaker code, it's possible to make string literal evaluations of code. A simple line such as the following can cause significant problems within any FileMaker solution.
If [ Get ( LayoutName ) = "Customer Details"]
As soon as you change the name of the layout to "Customer Detail" (without the "s") your code is now invalid.
To solve this issue we use the following.
No objects, in particular Layouts and Scripts, should be referenced within calculation code via string literals or absolute names. Internal Object IDs for common elements such as layouts and scripts should be used instead. A suite of custom functions for Object IDs should be used in place of string literals.
Fabrice Nordmann was the first developer to create a single function named ObjectID(). This single function, which handled multiple object types (Tables, Fields, Value lists, Layouts and Scripts) was then broken down into individual functions by Jeremy Bante.
This is an example of using an object reference within code.
If [ Get ( LayoutName ) = LayoutNameFromID ( "" ; 37 ) ] # Do layout specific steps here.... End If
Because Claris/FileMaker will never change underlying ID values (even when cloning a file), layout ID 37, which returns "Customer Details" will then return "Customer Detail" (minus the "s") after being renamed.
Given the above example; LayoutNameFromID ( "" ; 37 ) is far from decipherable.
This means you need to use the pair of custom functions, one which returns the internal ID as assigned by Claris/FileMaker, and the other which returns the human readable name (or number) - which is required by some script steps.
Use the custom function LayoutID ( file ; theLayoutName ) in order to first retrieve the internal ID for a given layout. Then create more readable code.
As stated, the goal of these standards is to create clear reading code. So, we use another custom function as a wrapper around these functions for certain implementations.
Given this poorly functioning code.
If [ Get ( LayoutName ) = "My Literal Layout Name" ] # Do layout specific steps here... End If
We opt for this...
If [ LayoutIsCustomerDetails ] # Do layout specific steps here... End If
Where the code inside of the custom function LayoutIsCustomerDetails reads as follows.
Get ( LayoutName ) = LayoutNameFromID ( "" ; 37 ) // originally named Customer Details
Variations of the above code can also result in the following. Where another custom function, named LayoutCustomerDetails is wrapped around:
LayoutNameFromID ( "" ; 37 ) // originally named Customer Details
We can then use the Go to Layout [by name...] script step as such.
Go to Layout [ LayoutCustomerDetails ; Animation: None ]
This method of coding, based on references, is highly resilient with regards to the flexible renaming supported by most of Claris/FileMaker development.
Going beyond Layouts
Requires you only to move to the TableID and TableNameFromID functions. Using these two functions you can use code which is context (Table Occurrence) based instead of Layout based.
Here is an example of a context based evaluation where code determines if a given Table Occurrence is currently being used. It is not limited specifically to a given Layout.
If [ ContextIsCustomers ] # Do stuff here. End If
Where the custom function ContextIsCustomers includes:
TableID ( "" ; Get ( LayoutTableName ) ) = 1065089 // references Customers Table Occurrence
The above code allows you to confidently execute code only when the user is within the proper context. Meaning any of multiple layouts can be associated to the given Table Occurrence being referenced in the current Layout.