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.
As soon as you change the name of the layout to "Customer Detail" (without the "s") your code is invalid. To solve this issue:
- No objects should be referenced within calculation code via literal strings or absolute names. The ObjectID custom function (created by Fabrice Nordmann) is used as an abstraction to reference FileMaker objects.
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".
Using the ObjectID custom function should not be handled in a direct manner. In order words. 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:
Where LayoutIs[nameOfLayout] is the prefix to all custom functions used to verify the layout. Here is the LayoutIsCustomerDetails custom function.
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.