Database Reference
In-Depth Information
POWER USERS' CLINIC: CONTEXT INDEPENDENCE
You may be wondering why the Send Email script you created on
Branching with If, Else If, Else,
and End If
doesn't go to the Customers layout first. After all, doesn't it only make sense from this
context? Actually, this script is a perfect candidate for
context independence
. If you run this script
from the Jobs layout, it creates a new email message addressed to the
related customer
. The same
holds true from the Invoice layout. In fact, you can run this script from
any
layout, and get a useful
result: FileMaker finds the related customer record, and addresses the message to her.
It's important to know who'll get the email if there's more than one related customer record. (Re-
member, the “Send Email to Customer” script is set to send only one email, even though the
Send
Mail
script step lets you send multiple emails to all customers in a found set.) As you'd expect, the
answer depends on the starting context when the script is run. If you run the script from the Scripts
menu, FileMaker selects the
first
related customer for the active record on the current layout. If the
relationship to Customers is sorted in the Relationships tab of the Manage Database window, then
it's the customer that sorts to the top. Otherwise, you get the first (oldest) customer record.
But if your layout has a portal of related customers, a button on the portal determines the context
from which the script runs (you created a similar button in a portal on
Go to Related Record
)
. When
you click this button, the script addresses the email to the customer in the portal line corresponding
to the button you clicked.
The point is, you can put a button just about anywhere and tell it to run this script. FileMaker does
something a little different depending on where the button is. So this example is one of those scripts
that you
don't
want to associate with a specific layout.
If it isn't before noon, the script does a second test to see if it's before 6 p.m. If it is, the user
sees a “Good Afternoon” message, and the script jumps to the end. But if both tests fail, no
third condition is tested, and the
Else
just shows the “Good Evening” message, like an auto-
matic condition in a
Case
statement. However, you can add other
Else If
steps to test other
conditions.
You can add as many
Else If
steps as you want, but they have to come between the
If
and
End If
steps. Each
Else If
can test a different condition. If you have an
Else
step, it
should come after the
If
and every
Else If
, but before the
End If
. You can think of the
Else
condition as the default condition in a
Case()
or an
If()
statement when you write a
calculation.