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. MX Kollection 3 offers yet another tool to perform this task: the Check Master Record server behavior .

To add this functionality to your site, and thus make the insert contact page bullet proof, follow the next steps:

  1. First off, open the insert page from the contact folder in Dreamweaver's editable area.
  2. You should already have the Insert transaction on page, from the previous section of this tutorial. This is needed, as the Check Master Record uses transaction data for its configuration.
  3. Apply the Check Master Record server behavior. Access it by clicking on the Plus (+) button on the server behaviors tab, and then going to MX Kollection -> Form Validation -> Check Master Record.
  4. Configure the server behavior, by setting the options in the dialog box that opens. The user interface is divided into two tabs: Basic, containing options about the tables and fields to use, and Advanced, with options regarding the trigger properties. As the latter is automatically set up, you will only have to deal with the Basic 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:


                                              
  5. Click on the OK button to add the server behavior to the page.
  6. 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.