Search through blog..

Sunday, October 28, 2012

Transaction Tracking System (TTS) in Dynamics Axapta

Transaction Tracking System normally referred to as TTS is used for tracking transactions. The idea is to secure the entire transaction to be committed to the database. This is vital for a relational database and even more for an ERP system. 

To say, while performing an invoice posting you must ensure that this does not result in corrupt data if the system crashes. TTS secures that all database operations within a TTS loop are committed entirely or not at all committed. 

Every time you are performing an insert, update or delete you should use the TTS. In fact you cannot update a record without doing it in a TTS loop. And every ttsbegin should have a ttscommit, if not provided an error will be thrown.

The below figure is to illustrate the working flow of TTS in Dynamics Ax:
Example (1):
static void DataDic_UpdateRecord(Args _args)
{
MyFirstTable myFirstTable;
;
try
{
    ttsbegin;
    select forupdate firstonly myFirstTable;
    myFirstTable.custName = "Customer updated";
    if (myFirstTable.validateWrite())
    myFirstTable.update();
    ttscommit;
}
catch(Exception::Error)
{
    ttsabort;
    throw error("@SYS93835"); //operation cancelled
}
}
Here, the first record in MyFirstTable is fetched and the field custName is changed before updating via the ttscommit.

If you need to update a record you must always fetch the record using the keyword forupdate in the TTS loop. A common mistake made when selecting forupdate is to fetch your data for update before calling ttsbegin. If you do this an error will occur.

No comments: