Overview

Within FileMaker code, it is possible to make literal evaluations. 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 invalid. To solve this issue:

The good code above will self-adjust when the name of the Layout is arbitrarily changed - as opposed to the literal reference of "People: Customer Details".

Implementation

Using the ObjectID custom function should not be handled in a direct manner. Your code should not make the calls shown above. The goal of these standards is to create clear reading code.

The ObjectID custom function should be added as a private custom function using the tilde nomenclature. ~ObjectID. This provides the immediate indication that this function is called by other functions and not directly.

This best practice suggests you use a "class prefix" for custom functions which deal with certain FileMaker elements. Here is an example of script code:

If [ Get ( LayoutName ) = LayoutIsCustomerDetails ]
    # Do layout specific steps here...
End If

Where LayoutIs[nameOfLayout] is the prefix to all custom functions used to verify the layout. Here is the LayoutIsCustomerDetails custom function.

// Object reference to Customer Detail layout

~ObjectID ( 4 ; "Layout" ; Null ; Null )

Where the value of "4" was determined by using the same ~ObjectID custom function within the Data Viewer in the format of ~ObjectID ( "Customer Details" ; "Layout" ; Null ; Null ) in order to determine the internal id of the Layout.

To optimize the code even further, your LayoutIsCustomerDetails custom function would directly evaluate if the current layout was the right target.

// Custom function code
Get ( LayoutName ) = ~ObjectID ( 4 ; "Layout" ; Null ; Null )

// Resulting script If[] step
If [ LayoutIsCustomerDetails ]
    # Do layout specific steps here...
End If

ObjectID Custom function on Github

Make note that, while titled Layout references, this information and the ObjectID custom function work with many other FileMaker objects, such as Tables, Fields, Scripts and Value lists. Use this information to accommodate these objects in a similar fashion.