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

Notifications

Announcements

No record found.

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 (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,160 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,438 User Group Leader 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
    237,880 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
    237,880 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
    237,880 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 611 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 529 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans