Problem setting createdon and overridencreatedon using overriddencreadon in crm 2011 RRS feed

  • Question

  • Hi all,

    I have a question regarding overriddencreatedon field. According to this link:


    I wanted to set the createdon to 2012/02/22 at the the of creation of a record for one of my entities. So in my code I Set overriddencreatedon to 2012/02/22.

    My exception was Createdon =2012/02/022 and OverridenCreatedOn = Current Date

    Instead the actual result was Createdon =Current date and OverridenCreatedOn = null

    Below is my code which is registered on the Create pre operation of my entity. Am I doing something wrong?

    My code

     public class AutoNumber : IPlugin

            private static string mib_ConnectionString;
            #region IPlugin member
            public void Execute(IServiceProvider serviceProvider)
                // Obtain the execution context from the service provider.
                var context = (IPluginExecutionContext)

                var serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                var service = serviceFactory.CreateOrganizationService(context.UserId);

                //Check the plugin message
                if (!(context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity))
                    throw new InvalidPluginExecutionException("Plugin is not registered correctly. Please contact your administartior.");

                if (entity.Attributes.Contains("overriddencreatedOn"))
                    entity.Attributes["overriddencreatedOn"]= new DateTime(2012, 2, 22);
                    entity.Attributes.Add("overriddencreatedOn", new DateTime(2012, 2, 22));

    Monday, October 20, 2014 6:27 PM

All replies

  • hello, what update rollup are you on?.

    if you are under 16, you may have to upgrade.

    also, is the user a system administrator?.




    Monday, October 20, 2014 11:09 PM
  • Thanks you for your respond. I am on roll up 16 and  am system administaror
    Tuesday, October 21, 2014 12:12 AM
  • Can you please try overriddencreatedon all small?


    Tuesday, October 21, 2014 12:34 AM
  • if (entity.Attributes.Contains("overriddencreatedon"))
                     entity.Attributes["overriddencreatedon"]= new DateTime(2012, 2, 22);
                     entity.Attributes.Add("overriddencreatedon", new DateTime(2012, 2, 22));



    Tuesday, October 21, 2014 12:58 AM
  • Thank you so much for the reply I made all lower case  

    the actual result is changed now, OverriddenCreatedOn  is not empty any more but still is not correct :

    Actual  Result: CreatedOn = Current date and OverriddenCreatedOn = 2012/02/22

    Expected Result: CreatedOn = 2012/02/22 and OverriddenCreatedOn = currentdate

    Any idea?

    Tuesday, October 21, 2014 11:21 PM
  • Hi Maryam,

    It should swap the value. When we set a value in overriddencreatedon the createdon field will be set to new value while overriddencreatedon will receive the datetime the record was actually created.

    Can you show the screen shot of the fields?

    Would you please try setting both the fields while creation? It doesn't make sense but we can try.

    entity["createdon"] = new DateTime(2012, 2, 2);
    entity["overriddencreatedon"] = new DateTime(2012, 2, 22);


    Kalim Khan

    Wednesday, October 22, 2014 6:10 AM