Linking transactions

One more improvement in the Transaction Engine 3 is the ability to link two transactions, and this way, to insert data into two tables at the same time.

In order to insert/update into two tables at once, the two separate transactions must be added first. This can either be with the wizard, or with the Server behaviors and Dreamweaver tools. One mention has to be made concerning the second (also known as detail) transaction: all fields must be displayed on the form, including primary and foreign key.

After creating the two transactions, you must apply the Link Transactions trigger, which will pass the first's transaction primary key as the second's foreign key and will submit them both.

The code behind this trigger is similar to the one shown below:

//start trigger LinkTransactions
function KT_TriggerAFTER_LinkTransactions(&$tNG) {
global $ins_contact_con;
$LinkTransactions = new tNG_linkedTrans($tNG, $ins_contact_con);
$LinkTransactions->setLink("idcom_con");
return $LinkTransactions->execute();
}
//end trigger LinkTransactions

 

As you can see, it is an after trigger, that executes only after the first (master) transaction took place and inserted data into its table. It then passes the primary key to the foreign key , which is used to determine the link in the setLink method. It is also an error trigger, as if anything happens, it will roll back the executed transaction(s).

The link transaction trigger registers itself to both transactions on page.

Just as for any other Transaction Engine 3 trigger or transaction, all code works with objects and methods, and this shows in the clear code.