Dynamics Ax modifying CreatedDateTime

For testing purposes with the MRP we needed to modify the createdDateTime fields in Dynamics Ax 2009. Since these are system fields we needed a workaround.

if(isRunningOnServer() && CurUserId() == "Admin")
{
            new OverwriteSystemfieldsPermission().assert();
 
            salesLine.overwriteSystemfields(true);
                                                                             // "YYYY/MM/DD HH:MM:SS"
            salesLine.(fieldnum(SalesTable,CreatedDateTime))    = str2datetime( "2010/04/03 11:00:00" ,321 );
            salesLine.doInsert();
            salesLine.overwriteSystemfields(false);
 
            CodeAccessPermission::revertAssert();
}

Remarks:

  • Make sure that it is running on the server tier
  • It only works on insert NOT on update

Since this code is pretty exotic and you don’t want to release this to a production environment we eventually didn’t use this but ran some sql jobs, but this shows that it is possible.

edit
Easy does it 😉

DECLARE @DATAAREAID nvarchar(4)
DECLARE @SALESID    nvarchar(20)
DECLARE @DATETIME   datetime
 
/* EDIT THE FIELDS BELOW */
 
SET     @DATAAREAID     = 'CEU'
SET     @SALESID        = '00003352_058'
SET     @DATETIME       = '01/01/98 00:00:00.000'
 
/* DO NOT EDIT HERE */
 
UPDATE  dbo.SALESTABLE
SET     CREATEDDATETIME = @DATETIME
WHERE   SALESID         = @SALESID
AND     DATAAREAID      = @DATAAREAID;
 
UPDATE  dbo.SALESLINE
SET     CREATEDDATETIME = @DATETIME
WHERE   SALESID         = @SALESID
AND     DATAAREAID      = @DATAAREAID;