Experiences on CRM, .Net and DHTML


  • Join Us on Facebook!
  • Follow Us on Twitter!
  • LinkedIn
  • Subcribe to Our RSS Feed

Dynamics CRM 2016 Online – Cannot insert duplicate key error (Possible causes and solution)

Very recently I was helping a business acquaintance of mine with their existing CRM Online implementation and I ran into a rather peculiar problem. I will describe the scenario first, then the error we faced and finally possible solution/workaround.

If your case does not fall in the scenario described here, there can be n number of reasons you are getting this error and you should start digging deep in traces logs or engage your CRM Administrator and/or Microsoft Support.


The client had multiple environments (Dev, Testing, Staging and Prod) which were cloned from 1 root environment and over the period of time they went out of sync (It is quite common to be these environments out of sync in terms of data as well as customization)
– however it was not tracked when they went out of sync. Now comes the strange part. There were certain records which needed to be migrated between two environments. I suggested we use standard import/export feature of Dynamics CRM. It should have worked but it did not.
We tried a lot but the files never went through and it never showed us any error. We gave up and as there were just 70 odd records, I whipped up a small utility that will take these records from source and push them to target. All set right? Well… NO.

Error and Troubleshooting:

I started getting error: Cannot insert duplicate key. I was surprised as the possible duplicate records were indeed not present in other environment. Dedupe rules were all disabled. Alternate keys were not defined. I disabled Activity Feed rules as well. Still no results.
As a last resort, I removed all the unnecessary attributes (which included some relationships) and taadaa… it all went in… except 1 record. After careful evaluation of both the environments I found that another record with the same GUID was already present (As I cloned records from other environment GUIDs were same).


So there were multiple reasons I was getting these errors in this scenario

  1. I had relationship attributes cloned, which retained GUIDs
  2. 1 record already had a duplicate record in the target environment. – As the environments were cloned their GUID seeds were same in each organization.


A possible solution here is to remove relationship data while you are cloning records and re-establish them after the records are created and also do a cleanup of record ID so you don't run in to the second case.

Releasing CrmXpress Theme Editor for Dynamics CRM 2016

I am very pleased to present new years' gift (although I am 10 days off of the mark ;)) from all of us at CrmXpress. As by the post's title you would have guessed, this is a theme editor for Dynamics CRM 2016.
The new theme editing features of Dynamics CRM 2016 is one of the well-received feature since 2015 update 1. Only challenge with the current editor is, you have to entre HEX values manually which can be problematic for non-technical users.

It is simple and straight forward to use. Still someone might find it useful so here is quick guide demonstrating how to use CrmXpress Theme Editor.

  1. Download the solution from here.
  2. Import the solution in your organization and publish it.
  3. Now, open the solution and you will see the screen below:

Figure 1 Configuration Page

  1. Click on Edit against the theme you want to edit and you will be presented with the editor.

Figure 2 Theme Editor

  1. Make desired changes and click on submit.

Figure 3 Theme Editor - Color Picker

Figure 4 Save the changes by clicking Submit

As theme editing in CRM is a new feature and we have external dependencies, this release is a Beta release. Please provide your valuable feedback/bugs/feature requests to help us improve and stabilize Theme Editor.

Update: CrmXpress Drag-n-Drop Upload Control for Dynamics CRM 2016/2015/2013

 have written a post detailing this control here so I am not going to write the whole story. I am bit surprised that Microsoft Dynamics CRM 2016 does not support drag-n-drop support yet. It allows you to upload templates for Word and Excel (maybe it is directly coming from OneDrive family). Anyways, here is a screenshot and a brief tutorial on how to use this control.

  1. Download the suitable solution from here.
  2. Import the solution in your organization and publish it.
  3. This control provides adding files via drag-n-drop to Email and Notes so you have to add (AttachmentsUpload.htm or NotesUpload.htm respectively) as a web resource.
    For example, in the screenshot below, you can see NotesUpload,htm has been added as a web resource for Contact entity form.

Figure 1 Add a WebResource on Form Designer

  1. Set Properties as shown below. Please note you must un-check Restrict cross-frame scripting, where supported and check Pass record object-type code and unique identifier as parameters.

Figure 2 Set Properties

  1. You can format the control as per your requirements. For recommended format options, see the screenshot below

Figure 3 Set Format

  1. Save the form and Publish Changes.
  2. When you are creating a record you will see appropriate message is displayed.

Figure 4 Create Record

  1. Once the record is saved, you can start using Drag-n-Drop to upload files.

Figure 5 Saved Record


Happy Holidays J

Microsoft Dynamics CRM migration from On-Premises to Online

Microsoft is adhering to the cloud first strategy for Dynamics CRM. There has been an increased time gap to when the CRM On-Premises customers receive the new features (or even bug fixes) as compared to the CRM Online customers. There are also features like Office 365 integration, Social apps etc., which are better suited for CRM Online users. This has triggered an interest among the CRM On-Premises customers to migrate to CRM Online. There could also be a number of other reasons like reduced infrastructure cost, maintenance etc. Moving to CRM Online isn’t just a database restore as Microsoft will not support that. Instead, the Solution files must be imported and the data has to be migrated. Here are a few things to plan for

  1. License: Licensing is different for CRM Online and On-Premise. A Microsoft partner can help you get the required licenses. Ideally, licenses (cost) should also be a factor in making the migration decision.
  2. Customizations: Import any managed solutions that you may have into CRM Online. Then import the unmanaged solution from the On-Premise version.
  3. Data Migration: Depending on the amount of data and the complexity of the data structure, you can choose from Import wizard, SSIS based migration (Kingswaysoft), or use third party tools is Scribe/ Synchronicity Echo. This step is the complex one of all. In that, fields like system fields ( like ModifiedOn, ModifiedBy, ActualClose, ActualStart etc.), have to be taken care of, record status (especially activities) might have to be set, multiple currencies and exchange rates have to be managed, plugins/workflows might have to be disabled during the data migration.

It is also worth noting that, if you are upgrading in addition to migration ( moving from an older version of CRM On-Premises to CRM Online), then an analysis of whether the features in new version can alleviate the existing customizations will be beneficial. This is also a good time to check on what exactly is being used/unused in the CRM implementation.

If for some reason, you decide to go back to CRM On-Premises, all you need is to request the support team for a database backup and restore it on the On-Premises instance. Here is a document that details the steps needed for migration. Keep in mind that you might not be seeing some of the features that were available on CRM Online but not yet released in the On-Premises version.