You can get only so far with your scripts by working with field values. Eventually you need to deal with more than one record. Thankfully, FileMaker has script steps for creating, duplicating, and deleting records; navigating among existing records; and even managing the process of opening and editing a record, and saving (committing) or reverting the changes. You can also work directly with portal rows on the current layout—and the records they represent.
Power Users' Clinic: Why Set Next Serial Value
The Set Next Serial Value script step may seem odd to you. After all, if you want to set the next serial value for a field, you can just do it yourself from the Manage Database window. But this step can come in very handy in some situations.
Imagine you work in the auto parts business and you have 200 sister stores around the country. Each office has its own copy of your database, which gets updated periodically. You have to send a new empty database to each store with all the latest enhancements, and the folks at each store have to import all the data from their old databases into the new one (you'll learn about importing and exporting data in Chapter 17).
Now suppose this database includes an Orders table with an Order ID field. After the old orders have been imported, the database might have orders with IDs from one to 1000, for example. But since no new records have been created yet, the Order ID field still has a "next value" of 1. The store's first thousand orders use IDs that are already used by other records. That's a big no-no.
The solution's obvious: You need to fix the "next value" on the Order ID field after the import's finished. To save the store manager the trouble, you can put a script in the database to fix this glitch for her. (In fact, you can make a script that does all the work of importing old data and fixing next serial values in every table.)
New Record/Request and Duplicate Record/Request have no options, and do exactly what you'd expect. The first script step creates a new record, just like the Records→New Record menu command. The second duplicates the current record. In either case, the new record becomes the current record, just like when you do it manually. You use these steps most often on buttons, when you're taking away menu commands from people and providing them with buttons that appear only on the layouts where you want people to be able to create records.
Duplicating a record from a script step works just like doing it manually—that is, the script duplicates the static (non-calculated) values in the record, too. If calculations depend on...