Basic Centralized Scripting

January 17, 2010 by Sameer

One idea commonly overlooked in the new FileMaker engine is the ability to centralize scripts. For example, instead of writing a dozen or so “Go to related…” with some table name at the end, I have the ability with script parameters to write one single script called “Go to” which uses a series of If, Else If, Else statements. This is available in previous versions of FileMaker, however with the addition of a script function called “Set Field by Name” I can go even further with my centralized scripting to include scripts such as “Create New Related Record.” This script, using the Set Field by Name function allows for a single function to handle the process of selecting which field to set, and what to set it to.

In this example we are going to be using script parameters and variables, and some calculation functions to make this work effectively. I have a database setup to handle Customers, Addresses, and Customer Orders. My goal is to write one script that can handle the creation of related records for Customers, either the address or a Customer order. See below for the relationship Diagram.

Picture 1

Pretty straight forward, I am using a Primary Key for the Customer, _pk_CustomerID, and then linking that to the Foreign Key in Invoices and Addresses, _fk_CustomerID. If I am looking at Customers, and I want to create a related address I will need to copy the Customer ID, go to and create a new record in the Address table, set the Foreign Key Customer ID to the value I copied from Customer, and then finally I will have my link. Again, it’s a pretty straightforward process, and in a simplistic sense I would need one of these types of scripts for any related record creation. So how do I combine all of them into one script?

The fist thing to consider is the process of determining which button I pressed to run the script. To dynamically send info to a script, I need to use script parameters. In this situation, the buttons for each create related record will be running the same script “Create Related” except that I will pass a parameter with each. Depending on your database, the process of passing the parameter can differ, but in this example we will be using a simple process. Each button will pass the parameter of the related table occurrence name as the parameter. So for the related address button I use a parameter “Addresses” and for the invoices I use “Invoices.”

*Note – Due to naming conventions of table occurrences and field names, it may be required to pass more than one parameter to a script. By adding a character return in between the values, then using a parse function like GetValue ( listOfValues ; valueNumber ) where the listOfValues is the script parameter, and the valueNumber is the item number based on your order. If you decide to follow this option, using a convention, such as the layout name then the table occurrence name, should be followed for all parameters associated with the script (i.e. always the layout name, then the table occurrence name).

The Script:

Set Variable [$param; Value: Get(ScriptParameter)]

Set Variable [$id; Value: Customers::_pk_CustomerID]

Go To Layout [$param]

New Record/Request

Set Field by Name [$param & “::_fk_CustomerID”; $id]

If you have questions or you would like more information, please feel free to comment. Follow me on twitter – DC_FileMakerGuy


No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment