web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

How to update CreatedBy or ModifiedBy field

(0) ShareShare
ReportReport
Posted on by 260

Hello guys,

I have a web service that creates some records and the CreatedBy field of a table is populated using the admin user since there is no user interaction.

I'm already sending the CreatedBy value on the request, but I want to update the CreatedBy field on the table.

However, this is a system field and I cannot update it. There is any way to override it?
When I try to write x++ code it shows "The field CreatedBy is read only. A value cannot be assigned to it"

Thanks,

I have the same question (2)
  • Suggested answer
    nmaenpaa Profile Picture
    101,172 Moderator on at

    These fields always store the id of the user of the session who wrote the record. If you want to store some other information, you should put it in some other fields.

  • Sohaib Cheema Profile Picture
    49,668 Super User 2026 Season 1 on at

    Or change the Integration user to correct user id. Having configured admin user for integration will result in writing the relevant user id information in the tables.

  • Verified answer
    Martin Dráb Profile Picture
    239,805 Most Valuable Professional on at

    Maybe you want to run the whole thing in a context of another user. If so, use runAs().

    If you want to run under an integration account but pretend it was inserted at another user (which doesn't look optiomal to me), maybe you can use overwriteSystemField(). Like this:

    new OverwriteSystemfieldsPermission().assert();
     
    myTable.overwriteSystemfields(true);
    myTable.(fieldnum(MyTable, CreatedBy)) = '...';
    myTable.insert();

    By the way, using an admin account for this purposes sounds dangerous to me. I would use a dedicated user with just the permissions needed for the custom service - and no more.

  • ergun sahin Profile Picture
    8,826 Moderator on at

    static void changeCreatedBy(Args _args)
    {
        TestTable testTable;
        ;
        select firstOnly forUpdate testTable;
        ttsBegin;
        new OverwriteSystemfieldsPermission().assert();
        testTable.overwriteSystemfields(true);
        
        
        testTable.(fieldnum(TestTable,CreatedBy)) = "ergun.sa";
        testTable.doUpdate();
        testTable.overwriteSystemfields(false);
    
        CodeAccessPermission::revertAssert();
        ttsCommit;
        info("test");
    }

    Create a menuItem (Runon:Server,ObjectType:Job)

    community.dynamics.com/.../update-ax-system-fields-either-createddatetime-or-modifieddatetime

  • bois0155 Profile Picture
    260 on at

    Thank you guys, I believe I'll have to override it for now. To use runAs like Martin said I would have to do a lot of changes on the service.

  • Martin Dráb Profile Picture
    239,805 Most Valuable Professional on at

    I don't think that the second verified answer is correct. As far as I know, overwriteSystemFields() works only on insert, not update. Please let me know if I'm wrong.

  • ergun sahin Profile Picture
    8,826 Moderator on at

    I also knew like you, but I tried when I saw the update in the example. It worked without any problems. In the link, he/she didn't say that the menuitem should work on the server side. Need to pay attention to that.

  • Martin Dráb Profile Picture
    239,805 Most Valuable Professional on at

    Okay, thank you.

    Paying attention to running on server isn't needed anymore. D365FO doesn't have any client application to run X++ code on.

  • ergun sahin Profile Picture
    8,826 Moderator on at

    You got me there. I didn't tried at d365 ( but on ax 2012). I dont think but its possible this is not working on d365fo

  • bois0155 Profile Picture
    260 on at

    Hello guys, I just created a Runnable job to test it on D365FO and I couldn't update the field.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 503 Super User 2026 Season 1

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 487 Super User 2026 Season 1

#3
Subra Profile Picture

Subra 433

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans