Sunday 25 December 2016

Transaction Log - AX 2012 - Cannot create a record in Audit trail (TransactionLog)

 If you got the following error you might have for problems in the system sequence table.


 Just run the following in SSMS:



select * from SYSTEMSEQUENCES where id = -2

 and then

select * from TRANSACTIONLOG where CREATEDTRANSACTIONID > returnedID order by CREATEDTRANSACTIONID asc


 If you have any records returned by the second statement then you should look into why you have a lower system number saved.


To over come this issue, please find the below code modifications in Tables-->TransactionLog-->Methods-->create.
The existing Code:

if (appl.lastTransactionIdCreated() != appl.curTransactionId())
{
transactionLog.Type = _type;
transactionLog.Txt = _txt;

transactionLog.insert();

appl.lastTransactionIdCreated(transactionLog.CreatedTransactionId);

appl.transactionlogUpdateTTSControl().revoke();
}



The changes to make: 

if (appl.lastTransactionIdCreated() != appl.curTransactionId())
{
if (!TransactionLog::find(appl.curTransactionId()))
{
transactionLog.Type = _type;
transactionLog.Txt = _txt;

transactionLog.insert();

appl.lastTransactionIdCreated(transactionLog.CreatedTransactionId);
}
appl.transactionlogUpdateTTSControl().revoke();
}

http://axfaq.blogspot.com.eg/2013/09/transaction-log-ax-2012-cannot-create.html