Database Reference
In-Depth Information
POWER USERS' CLINIC: INDIRECTION
Script parameters let you write multipurpose scripts that you can use under many different circum-
stances. You just pass the script a parameter that triggers the branch that runs the parts you need,
based on the circumstance.
To take your FileMaker skills to the next level, you need to learn indirection . That term means refer-
ring to things—usually fields, but also named objects ( Go to Object ) —without specifically naming
them. The point is to make your scripts more reusable. For instance, a script that finds a record by
ID needs to search the CustomerID field in the Customers table, but the InvoiceID in the Invoice
table. Without indirection, you'd have to write two different find scripts, pointing to two different
fields, even if every other script step is exactly the same.
A special script step called Set Field by Name lets you put data in fields by indirection. To under-
stand how it works, look at the normal Set Field script step, which lets you specify a field to re-
ceive the result of a calculated value. For example, you might set the Zip Code field to a known
value, for instance, or set the Balance Due field to the sum of costs minus the sum of payments.
By contrast, the Set Field by Name step lets you specify two calculations. The second determines
the value to store, just like Set Field. But the first calc evaluates to the name of the field you want to
set. In other words, if the result of the calculation is “Customers::First Name,” then the step stores
its value in the First Name field. If the calc returns “Customers::Last Name” instead, then it puts the
calculated value in the Last Name field. Here's a formula that assembles a field name:
Get ( LayoutTableName ) & "::First Name"
This formula targets the First Name field in the table associated with the current layout. So this step
can work in a Customers table and an Employees table. Even better, you can use a script parameter
to pass the complete field name and then Set Field by Name uses that parameter to identify its tar-
get.
You can also fetch data from a field indirectly by using the GetField() function:
GetField ( LayoutTableName ) & "::First
Name" )
This formula grabs the value from the First name field based on the current layout you're viewing.
Finally, the GetFieldName() function helps you grab field names reliably. Suppose you need a
script that finds Invoices with today's date in either the Invoice Date or the Date Due field. You cre-
ate two different buttons to run that script, and type one field's name as the script parameter in each
button. Then you use Set Field by Name to put today's date into the specified field with
Get(ScriptParameter) .
You've used indirection, but this approach is unsafe. Since you're passing the field name in a calcu-
lation text value, FileMaker doesn't see it as a proper field reference and won't update the script
parameter if you rename the field(s). Now your scripts refer to a nonexistent field and they won't
Search WWH ::




Custom Search