To verify some customizations, you might need to change the system fields either CreatedDateTime or ModifiedDateTime. The purpose of this can be different.
I will provide you with the two options of changing system fields. First option allows you to change system fields at the moment of insertion new record. The second option allow you to change system fields in already created record.
Option1. Keep in mind that with this way you cannot update a system field once the record is been inserted in to table. You can only overwrite the values of system field at the time of insert only. That’s why example below shows you changing CreatedDateTime at the time of insertion – doInsert method.
1. Create the following job, but do not run this job so far
static void Job36(Args _args)
{
TableName tablename;
ttsBegin;
{
new OverwriteSystemfieldsPermission().assert();
tablename.overwriteSystemfields(true);
tablename.uniqfieldid = “IDValue”;
tablename.(fieldnum(TableName,CreatedDateTime))= str2datetime( “2010/04/03 12:00:00” ,321 );
tablename.doInsert();
tablename.overwriteSystemfields(false);
CodeAccessPermission::revertAssert();
}
ttsCommit;
}
2. Create an Action menu item
3. Set the following property for the item:
Object type = Job
Object = Job name
4. Run menu item
Option2. Update already created record.
Example below is allow you changing ModifiedDateTime in the already created record.
1. Create the class with the only one method main inside:
static void main(Args args)
{
str sql;
Connection conn;
SqlStatementExecutePermission permission;
;
sql = “update inventtable set ModifiedDateTime = ‘2009-05-25 00:00:00.000’ where recid=5637521851”;
permission = new SqlStatementExecutePermission(sql);
conn = new Connection();
permission = new SqlStatementExecutePermission(sql);
permission.assert();
conn.createStatement().executeUpdate(sql);
CodeAccessPermission::revertAssert();
}
2. Create an Action menu item
3. Set the following property for the item:
Object type = Class
Object = Class name
RunOn = Server
4. Run menu item
5. Create a job with reread() method in order reread the record, because in AOT you might see the wrong data.
Enjoy!