How to Modify the “Created On” Value of Dynamics CRM 2011 – Part 1

Vincent Zhong, 15 August 2012

In Dynamics CRM 2011, there are some fields that are not supposed to be modified by User or Program. Like “Created On” and “Created By”.  When you are creating a record, you don’t need to fill out those two fields. CRM will fill out those two fields based on the current User and the current time.

How to Modify the Created On Value of Dynamics CRM 2011 Part 1

But that is not always the ideal case for your business. Like last week I imported 50 Cases into my CRM organization for demo purpose. The “Cases by Priority (Per Day)“ chart will look like this:

How to Modify the Created On Value of Dynamics CRM 2011 Part 1

Because the “Created On” field of all my records have been set to the time I run the import.  So I need a way to modify it, so that I can get more useful information out from my chart. This blog post is the solution I found.

First I will show you how to modify the field programmatically. Here is method I created for experiment purpose:        

private static Guid ModifyCreatedOnDate()
        {
            DateTime lastYear = new DateTime(2011, 1, 24, 10, 30, 00);

            Entity contact = new Entity("contact");

            contact["firstname"] = "Modify";
            contact["lastname"] = "CreatedOn";
            contact["createdon"] = lastYear;

            return sdk.Create(contact);
        }

Now if I run this method, I have the following record created:

How to Modify the Created On Value of Dynamics CRM 2011 Part 1

As you can see, even I manually set the “Created On” field to “24/01/2011 10:30 a.m.” in my code, CRM will ignore my change and set that field to the current time.  The solution to this problem is, I need to use “Record Created On (overriddencreatedon)” field if I want to modify the “Created On(createdon)” field.

So I modified my method like this:   

private static Guid ModifyCreatedOnDate()
        {
            DateTime thisYear = new DateTime(2012, 1, 24, 10, 30, 00);
            DateTime lastYear = new DateTime(2011, 1, 24, 10, 30, 00);

            Entity contact = new Entity("contact");
            contact["firstname"] = "Modify";
            contact["lastname"] = "CreatedOn 2";
            contact["createdon"] = thisYear;
            contact["overriddencreatedon"] = lastYear;

           return sdk.Create(contact);
        }

 Let’s look at the result:

How to Modify the Created On Value of Dynamics CRM 2011 Part 1

Now the new record we just created has a “Created On” value of “24/01/2011 10:30 a.m.”. So looks like we did successfully modify that field.  Another thing we noticed here is the “Record Created On(overriddencreatedon)” field  has a value of “8/08 2012”, which is today.

So from the two experiments we did above, we got the following conclusion.

• If you just modify the “Created On” field in your program, it won’t do anything.

• If you change “Record Created On” field to the date value you want, that value will be copied to the “Created On” field, and the time you run your program will be populated into “Record Created On” field.

• CRM will check if the “Created On” field has been modified. If it is, it will use “Record Created On” field to keep a copy of the actually “Created On” value.

Hope you find this post useful. I will show you how to modify the “Created On” field when importing data using Import Data Wizard.