Quantcast
Channel: Dynamics AX
Viewing all articles
Browse latest Browse all 550

Over Writing System Fields (CreatedDateTime, CreatedBy....)

$
0
0
Here I am overwriting System Field - "CreatedDateTime"

Over writing of system fields will works only while we are inserting a new record in the table.
It will not work while updating a record.

NOTE : Since we require the "OverwriteSystemfieldsPermission" class permissions, we should run this on server so I wrote my job with the access specifier as "server" keep in mind that while doing this you should always run this on Server rather than on you local Client.

static server void getOrigSalesLineCDateTime(SalesId salesId)
{
Table1                   table1;
SalesLine               salesLine;
UtcDateTime         salesLineRecDateTime;
    ;
    select salesLine where salesLine.SalesId == salesId;
    salesLineRecDateTime = salesLine.createdDateTime;

    new OverwriteSystemfieldsPermission().assert();

    ttsbegin;
     table1.SalesId = salesLine.SalesId;
     table1.overwriteSystemfields(true);     table1.(fieldnum(Table1,createddatetime)) = salesLineRecDateTime;     table1.insert();
     ttscommit;

     table1.overwriteSystemfields(false);     CodeAccessPermission::revertAssert();
   }

EOJ

Please let me know your comments.....!

Happy Daxing...

Viewing all articles
Browse latest Browse all 550

Trending Articles