Database Reference
In-Depth Information
Figure 12-7. The window for the
Perform Find/Replace
script step looks a lot like the normal
Find/Replace
window. But this version has a new pop-up menu (called Perform) and a couple of
new Specify buttons that let you specify calculated values for what you're looking for and what you
want to replace the found results with.
GEM IN THE ROUGH: 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
im-
port
all the data from their old databases into the new one (you'll learn about importing and export-
ing data in
Chapter 21
)
.
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 1 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 is obvious: You need to fix the “next value” on the Order ID field after the import is
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.)
The script itself is simple, just two lines, but you need to do some prep work. First, create a
new table in your database, and name it Globals. Give it one field: a global text field called
“gSearch.” Don't forget to set the field option to use global storage (
Global Storage
). Place
this new field on the Customers layout above your Notes field. Set the field's behavior to be