How to overwrite system fields?

Hi all,

I wrote this code to overwrite createddatetime field.

ttsbegin;
select forupdate Salesquotationtable where Salesquotationtable.QuotationId==“IRF_00005570”;
Salesquotationtable.overwriteSystemfields(true);
Salesquotationtable.(fieldnum(Salesquotationtable,createddatetime))=datetimeutil::utcNow();

Salesquotationtable.update();
ttscommit;
Salesquotationtable.overwriteSystemfields(false);

but following error turns up.

Request for the permission of type ‘OverwriteSystemfieldsPermission’ failed.
(S)\Classes\OverwriteSystemfieldsPermission\demand
(S)\Classes\xRecord\overwriteSystemfields

can anyone help?

There are three things wrong that I can see.

  1. You need to first assert the permission, you can put above your first line this:

and after the last line

  1. It also needs to be run server side for the permission assertion to work. So put it in static server method or something.

  2. I don’t think you can update system fields. I think you can only do inserts. Just try it and see.

Why do you want to overwrite the system fields???

It is not possible to directly update the system fields. But there is an alternate way you can do it.

Do an update directly in the Database or execute a direct SQL statement by using Statement(API) class.

Note: Dont do it in case of the transaction tables and even in case of master tables if the trasactions exists for that - which may lead to data inconsistency…

thank for ur replies

@alex:

I tried these things too .But it dint work

@kranthi:

I will try to do updation in SQL.But they have given a method overwritesystemfields() ,so i thought why it is not possible to do in AX itself?May be i would need some permission,But it dint work ,giving whatever kind of permissions

It only works at the time of insert…

I tested this already, it works. You most likely still have it running client side. It must run server-side in order for the permission assertion to work. Create a class, Class1, then add your code inside a method called “static server void myMethod()”. Then from a job, call “Class1::myMethod()”. This will ensure it runs server side. It will only work for INSERTS and not updates.

Narayan,

The purpose is for database logging, importing data from other systems, etc. Take for example you have a 3rd party CRM system (i.e. SalesForce.com) that your users enter sales orders into. At the end of the night, you have a batch job in AX that imports all of the sales orders into your system. All of the sales orders will have a “CreatedBy” of your AOS user account, and not the actual users that created each sales order. This is an example of where you would overwrite system fields, and change the “CreatedBy” to the user that created the sales order, instead of the system account that’s importing the sales orders.