how to update the system fields of the table like ModifiedDateTime ?

Usually in the transaction table while data copying from older version to newer version, we require to copy the system fields as well like (ModifiedDateTime, ModifiedBy, CreatedDateTime, CreatedBy). These fields are system generated fields and user cant update the values in these fields In a normal manner. We have to do a bit trick to fool the compiler

Wrong way : Compiler will not allow this and give you the error “The field must be a data element that allows assignment.”

LedgerTrans ledgerTrans;  
 ;  
 ttsbegin;  
 ledgerTrans.modifiedDateTime = DateTimeUtil::utcNow();  
 ledgerTrans.update();  
 ttscommit;  

Correct way: you can make the compiler silent with below modifications

LedgerTrans ledgerTrans;  
 ;  
 ttsbegin;  
 ledgerTrans.overwriteSystemfields(true);  
 ledgerTrans.(fieldNum(LedgerTrans,modifiedDateTime)) = DateTimeUtil::utcNow();  
 ledgerTrans.update();  
 ttscommit;  
Advertisements

6 Responses to how to update the system fields of the table like ModifiedDateTime ?

  1. julio says:

    Hi Amir,

    I’ve got version 3.0 of axapta and sp3:

    I have a doubt about deleting a ledger transaction from ledgertrans table, there is a voucher that was inserted wrong with taxes included when the ledger account shouldn’t have taxcodes linked,but anyway it happened, so my idea is to delete thata voucher directly from ledgertrans and from taxtrans to erase the problem…my doubt is: ¿that will work right or is there a ‘cleaner’ method to do it without get into x++ or SQL?

    Thanks in advance and best regards,

    • Amir Nazim says:

      how do you make the ledger transaction ? i think through some journal. the simple and best way for this is to create a new journal same as original one but with -ve amount. this will void the affects from your ledger transactions.

  2. Absher Rashid says:

    CheeeeeeeeeeeeeeeeeeeeeeeeTA
    Thanks!!!

  3. Murali says:

    Hi Amir

    We got the same requirement to edit the system fields,
    When i googled found your post and it is very usefull.

    but however your logic works till the execution(seen by debugging) only(records getting updated), once the execution is over those field values are changing back to the original values.

    if any one knows how to prevent this
    let me know.

    thanks in advance.

    Murali

  4. Murali says:

    Hi Amir
    We got the same requirement to edit the system fields,
    When i googled found your post and it is very usefull.
    but however your logic works till the execution(seen by debugging) only(records getting updated), once the execution is over those field values are changing back to the original values.
    if any one knows how to prevent this
    let me know.
    thanks in advance.
    Murali

  5. Ramanathan V says:

    Hi Amir / Murali,
    Any solutions please. I am also getting the same result as Murali. Murali, Can you pl share how this issue is resolved?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: