Aug 16, 2016

Dynamics CRM Data Migration ModifiedOn


It was always a pain during data migration to get your modifiedon, modifiedby from existing data to CRM. Good News is some of our blogger comes up with solution. It was working for me for CRM 2016 online.

I was able to update modifiedon dates for my activities. Here is the approach and solution –

I have created dummymodifiedon field and got the actual modifiedon datetime values in that field during migration. I have used that to set my modifiedon date.

Here is the exact code I have used in my preplugin. That’s it you are good.

    public class MigrationPrePlugin : IPlugin
        public void Execute(IServiceProvider serviceProvider)
            var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            var factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

            var service = factory.CreateOrganizationService(context.UserId);

            // The InputParameters collection contains all the data passed in the message request.
            if (context.InputParameters.Contains("Target") &&
            context.InputParameters["Target"] is Entity)
                // Obtain the target entity from the input parameters.
                Entity entity = (Entity)context.InputParameters["Target"];
                entity["modifiedon"] = entity["new_dummymodifiedon"];

Here is the original blog post –

Happy Coding

No comments: