Verify
associated company: Check Master Record
When adding entries in a detail table where the user must manually enter
the foreign key value, accidents are prone to happen. Also, when you use
a drop-down menu, or any other way of deciding the foreign key value,
there is still the risk that between the page load, with the master record
options, and the actual insert, another user will delete the master record.
Since the retrieval of the options and the insert operation are two different
SQL transactions, and there will always be some time interval between
them, something might go wrong.
This is why you should check for the existence of the master
record
before the actual insert.
offers yet another tool to perform this task: the server behavior .
To add this functionality to your site, and thus make the insert contact
page bullet proof, follow the next steps:
- First off, open the insert
page from the contact folder in 's
editable area.
- You should already have the on page, from the previous
section of this tutorial. This is needed, as the uses transaction data for its configuration.
- Apply the
server behavior. Access it by clicking on the button on the server behaviors tab, and then going to .
- Configure the server behavior, by setting the options
in the dialog box that opens. The user interface is divided into two tabs:
, containing options about the tables
and fields to use, and , with options
regarding the trigger properties. As the latter is automatically set up,
you will only have to deal with the
options. The instructions below will guide you to quickly configure the
trigger:
· The Transaction table drop-down is automatically completed
with the table used in the insert transaction (contact_con
for this case), and disabled.
· In the
Foreign key
drop-down menu you must select the transaction table's field that ensures
the link to the master table. For this particular case, the field is idcom_con.
· In the
Master table drop-down menu select the database
table that acts as master for the transaction table. Select company_com.
· In the
Master primary key drop-down menu select
the master table's field containing the primary key: id_com.
· You will
also have to enter an Error message, that
will be displayed when the master record check fails. Enter a suggestive
text (e.g. "The selected company does not exist!").
· If you've
followed the instructions above, the dialog box should look like this:

- Click on the button
to add the server behavior to the page.
- You can now save your page and upload it to the server.
If you wish to test the newly added server behavior, open the insert
page in a browser window, and in another window delete the company. When
submitting a new contact for that company, you will receive an error message.