Migrating / Importing data and maintaining Created By, Modified By and Modified On
When importing or migrating data to a Dynamics 365 / CRM environment you cannot migrate the fields Created By, Modified By and Modified On. Most customers won’t bother about it until it comes down to the migration of ‘old’ activities. By default, the Social Panes show activities sorted on the Modified On date. So when you migrate data and all activities have ‘today’ as the Modified On date, you’ll get problems with the sorting of activities.
Migrating the data and setting the fields
As you know, it’s not possible to set the values of the Created By, Modified By and Modified On date. That is when you try to set this data directly. Lucky for us, when using the SDK it is actually possible to set the values of those fields. The solution contains a plugin that does this:
- At the creation of a record, check if the field ‘dnbs_overriddencreatedby’ contains a value. If so, set the field createdby to that value.
- At updating a record, check if the field ‘dnbs_overriddenmodifiedby’ contains a value. If so, set the field modifiedby to that value.
- At updating a record, check if the field ‘dnbs_overriddenmodifiedon’ contains a value. If so, set the field modifiedon to that value.
In order to make this work for your data migration or data import, just make sure you set the values of the fields ‘dnbs_overriddencreatedby’, ‘dnbs_overriddenmodifiedby’ and ‘dnbs_overriddenmodifiedon’. These are the schema names of the fields. The display names are: Overridden Created By, Overridden Modified By and Overridden Modified On. When you import the solution, these fields are available on these entities:
- Appointment
- Letter
- Phonecall
- Taks
The solution is extensible
The plugin inside the solution is setup to fire off on all entities. This means that you can extend the use of this plugin to all other entities. When you want to use the same method on the Account entity, for instance. You just need to make sure you create these fields on that entity. The schema names of those fields must exactly match these names.
- dnbs_overriddencreatedby as a Lookup to the User entity;
- dnbs_overriddenmodifiedby as a Lookup to the User entity;
- dnbs_overriddenmodifiedon as a Date and Time field.
Don’t forget to delete the solution!
When you are done with migrating or importing your data, don’t forget to delete the solution! As you have seen above, the plugin fires off at all updates. This is a loss to your performance and also you might get into trouble with the Modified By and Modified On fields not being updated right.
32 Replies to “Migrating / Importing data and maintaining Created By, Modified By and Modified On”
Hi Marc, your override modifiedon Plugin only seems to work for Closed activities, and does not work for open activities? Will you be planning on fixing this anytime soon, or shall I develop a fix for this which im happy to do?
Many Thanks for your effort!
Hi Raz, the solution works for both open and closed activites with me. Is there anything else that might be blocking here? I’ll be happy send you the sourcecode if you want to 🙂
Hi Marc I can confirm this solution works as expected, I think the Asynchronous service took some time to catchup with large data loads but the modifiedon and createdon dates do eventually get updated. Thanks again!
hi
I am not able to import this solution to crm 16 onpremise environment
Hi Archi, it should just work. Any errormessages coming up?
Will this work with earlier versions? We are currently running version 8.0.0.1088. Thanks Ken
Hi Ken, I think it should work from version 8.0 onwards. Just try and you’ll know 🙂
Hi Marc,
Thank you for the brilliant solution. I did tried this and initially modified on date placed in Override Modified On field then once I do the update to the record then original datetime from Override Modified On field is transferring on to Modified On field.
Is it possible to transfer the Modified on field date from OverrideModifiedOn onto Modified On without doing any updates.
Please suggest!!
Hi Krishna,
Sorry for my late response. The only wat to update data without doing an update is updating the SQL tables. Obviously that can’t be done in an Online environment, but it can in an OnPrem environment.
Hi Marc,
This solution work for only completed activities for us. Can you please give some guidance please ?
Thanks
Rasha
Hi Rasha,
Can you check the plugin steps? I’m not sure about the steps. Maybe the steps in the solution are only on statechange and not on create/update.
Hi Marc,
Great idea for a solution.
We are having a similar issue with updates to modified by and modified on.
I can only seem to get it to update close\completed activities.
If the activity is open and we have data in the override (modified) fields nothing happens.
if we then export the date and change the status to close/completed the update works for the override modified fields.
Is this expected or are we missing something?
Any help would be appreciated.
We are using the latest version of D365 online V9
Thanks,
Peter
Hi Peter,
Can you check the plugin steps? I’m not sure about the steps. Maybe the steps in the solution are only on statechange and not on create/update.
Also good to know is I haven’t tested the solution on V9, although I think it should work. Can you let me know if it works for you?
Hi Marc,
This solution looks great, but it can’t be imported into a v8.1 environment (CRM 2016). Is it possible for you to provide a copy of the managed solution that could be used in an earlier environment?
Cheers,
Ryan
Hi Ryan,
I’ve send you the source code. Can you let me know if this works out for you?
Cheers,
Marc
Great post Marc! just wondering how to deal with Notes since it cannot be customized.
Haha thanks! I have to admit I haven’t thought about the annotation entity before. You’re right my solution doesn’t work for this entity… I’m afraid I don’t have a solution for this yet
Hi Marc,
it sounds to be a great solution for my import problems, but I don’t get it work.
I’m working an a D365 platform (V9) and successfully imported the solution.
I imported some previously exported datasets and assigned (only) the modified on date to your field in the email object.
The reimport was successful, but the date did not change.
Is there anything to do to trigger the task?
Cheers, Bernd
Hello Marc,
all SDK entities seem to be imported, the objects have the additional fields, but there are no updates on my (email) objects, when I import them via Excel.
Fields are sucessfully filled.
I’m using D365 V9.
Is there anything to do after importing the solution?
Cheers, Bernd
Hi Bernd,
Sorry to not coming back to you any sooner. Apparently my e-mail notification don’t work anymore since I didn’t receive an e-mail of your comment.
I have to admit I haven’t tested the solution on v9 yet, but think it should work. Two questions here:
– Do the custom fields have a value (i.e. ‘Overridden Modified On’)?
– Has there been an update on the email? Maybe the record has only been created. I thought it would only work on an update.
Let me know!
So, once the legacy data has been imported into CRM into my custom entity, I delete the solution; but can I delete the three fields as well?
Also, do the modified by and created by users need to be created as actual system users in CRM? I have legacy users who have long since gone. Do I need to pre-create these users in CRM before importing? If so, can they be de-activated users?
Thanks
Hi Lorne,
Yes, please delete the three fields. If you don’t the ModifiedOn will never change.
You can pre-create the legacy users as stub-users. Microsoft has this solution in place for you. Simply just import the users via Excel. They won’t be able to login, but you will have the users in place for migration purposes. See also https://docs.microsoft.com/en-us/dynamics365/customer-engagement/admin/create-users-assign-online-security-roles#how-stub-users-are-created
Does this add-on still work in Version 1710 (9.1.0.35) online? It always worked fine, but now my fields values are not being updated.
Hi Michel,
I’ve tested it on 9.1 and seems to work fine for me. Have you found another issue or is it still not working?
Cheers,
Marc
Hi Marc,
Hi Marc,
Thanks for your solution and this post. I am in the middle of creating a similar plugin but came across your article and decided to download and give it a go. One thing I noticed if I want to extending this to other entities, when I create new field, the prefix is either new_ or something else depending on the publisher not dnbs. Yours is a managed solution so I could not add any new entities to it. I cant create new solution either with the same publisher name as the its a managed solution publisher. If I have any issue with my custom plugin, and If decide to use yours, do you think you will be able to give a link to download the un-managed version of the solution. Please note I am ok with deleting components one by one after the migration.
Thanks
Hi Kokulan,
Sure, not problem! Here’s the link to the unmanaged solution: https://marcgerner-my.sharepoint.com/:u:/g/personal/marc_marcgerner_nl/EfMuj9EbxZdGg7IVVywfk1kBMaSrUgDiL-Ucm5Nj3dCmMw?e=IAjHQb
Cheers!
Hi Marc,
just about to give your tool a try but read your comment about annotations. Did you figure out how to set these too meanwhile?
Hi Leif,
Unfortunately there is no way to do this for the annotation entity. We just have to deal with incorrect data there 🙁
Hi Marc,
What a brilliant solution – I had this working as expected for activities, but when testing it on Case entity, I didn’t have luck. It appeared to me any regular update on Case record still works, but when it comes to closing/resolving the case, or changing the owner manually, the plugin didn’t work (interesting enough, using the assign button still works in my case). Anyway if you can provide any insight, that’ll be great.
Thanks,
Jack
Hi Jack,
Thanks for the compliment!
Regarding your issue: I have an idea, but not enough time to test it today. So if you could test it, let me know if it works. You need some development skills for this resolution so I hope your dev-skills are in place :-).
My custom code runs when a record is created or updated. When you develop code for Dynamics 365 (or CDS / Dataflex Pro as it is called these days) you have to bind your code to a so-called ‘message’. There are messages for creating or updating a record and I bound my code to both these messages. However, some actions in CDS are bound to entirely different messages! You would expect the close of a Case record is within the update message, but it is not. Closing a Case record is a ‘close’ message. You have to bind my code to the ‘close’ message by adding an extre step in the plugin with the plugin registration tool. I think when you do so, everything works just fine.
Please let me know if it worked out for you!
Cheers,
Marc
Thanks for the insight, Marc. I should have thought of the “close” message, as I was trying the setstate/setstatedynamicentity combo. Meanwhile, I found a workaround, as long as the update can be triggered once again, your plugin will work. (just some background, I was using Kingswayssoft to import data, I have one step to upsert Cases, by adding an extra step to force the update triggered your plugin, so I am happy with the result). Thanks!
Quick tipp. After the first import run with this solution it did not work as expected for the modifiedon and modifiedby fields. They where filled with the current time and the admin user.
After analyzing the PlugIns that are activated on the system, I realized that the problem was, that there are other PlugIns running after this one and therefor overwirting the modifiedon and modified by fields again.
Deactivating the “Microsoft.Dynamics.Playbook.Plugins.PostOperationPlaybookActivitiesCreateUpdate” STEPS for the migration worked out for me.
Thank you Marc for that great Solution!