Dynamics AX Transaction scope and UserConnection class

We have done some customization in AX which perform insertion and updating data on multiple tables. It oftens fails and we have no clue where it fails so we decided to implement logging just for knowing how much steps are performed up till and if it fails where did we fails.
We decided we will create separate table for logging and records every step in table which is about to performed so in this way we detail about steps.
Normally we perform all activity in one transaction so if something fail whole process should be reverted but we want that our log should persists in table.
There is a class UserConnection which exactly do what we wanted it to do. You just have to create its instance and on table just mention that it AX should use this new connection for this particular table. I am giving you an example.
 
 static void SampleUserConnection_Job(Args _args)   
 {  
      VendTable vendtable;  
      MyLogTable myLogTable;  
      UserConnection userConnection = new UserConnection();  
      ;  
      ttsbegin;  
      vendTable.AccountNum = 'Test-0001';  
      userConnection.ttsbegin();  
      myLogTable.clear();  
      myLogTable.setConnection(userConnection);  
      myLogTable.detail = "going to create new vendor";  
      myLogTable.insert();  
      userConnection.ttscommit();  
      //set some other field value  
      vendTable.insert();  
      throw error('throwing error just to revert transaction but log table should have data');  
      ttscommit;  
 }  

Comments

Popular posts from this blog

X++ Get Start Date and End Date of Month

Dynamics AX 365 : The name does not denote a class, a table or an extended data type

Error while setting server report parameters. Error message: The permissions granted to user are insufficient for performing this operation. (rsAccessDenied)