[CRM 2016] Error code #0x80040237. Error while solution import. Cannot insert duplicate key.

We were deploying from sandbox to production with one of the solutions. And for no reason, the solution import failed on all attempts with error code #0x80040237. And there was not much description given except – “Cannot insert duplicate key”. This was the error on one of the entities.

First, we followed a post by a friend on the same error. We even removed some data to check if that is the case. But, the import failed again with the same error code and description.

Then, we came across similar question on MSDN. Question was already showing an answer that by removing <CustomControlDefaultConfigs> section from Solution.xml this can be resolved. This issue is already taken care on Dynamics 365. However, CRM 2016 Online, this issue still persists.

Resolution:

  • Extract your solution zip file.
  • Open solution.xml file in a text editor.
  • Search for the <entity></entity> tag for the entity on which your solution import is showing the error.
  • Find and remove <CustomControlDefaultConfigs> section inside the <entity> section.
  • Save the solution.xml file and create new zip file from the extracted solution contents.
  • Import will be successful this time!!

The reason to remove <CustomControlDefaultConfigs> section from solution.xml file is still not known. And there are other option also available like updating sql to resolve this error for on premise deployments. However, CRM Online users do not have any option but to modify solution.xml file.

Hope this helps!

Advertisements

Access to Microsoft Dynamics CRM has not yet been fully configured for this user. The user needs at least one security role before you can continue.

I ran into an issue when I was importing a different version  of solution to the organization. The error was:

Access to Microsoft Dynamics CRM has not yet been fully configured for this user. The user needs at least one security role before you can continue.

I was not able to find anything on google/bing for the specific error, but one of the blog I found said the error can be from business rules or other type of processes.

After some research, I came to know that there were multiple Business Rules on the organization which were owned by users who were deactivated and no longer have anything to do with CRM Development.

Resolution:
To resolve this issue, you just  need to assign the Business Processes or other workflows to any active user.

Step 1: Use Advanced Find feature to find the processes and their respective owners.

Advanced Find - Business Rules
Advance Find Business Rules

 

Step 2: Select all results which shows owner who are already disabled.

Advanced Find Result

Advanced Find – Result

Step 3: Assign the Business Rules/Processes to your user account or another user who is in active state.

Assign

Assign processes

And you’re done!! Try to reimport the solution and the error will be gone forever…

CRM 2016 + JavaScript: Web Resource cannot be reloaded

Since we got upgraded to CRM 2016 from CRM 2015, we faced a strange issue with JavaScript and Web Resource (html).

At some point of time the script goes to reload the html Web Resource with the following code:

var webResource = Xrm.Page.getControl("WebResource_ControlName");
webResource.setSrc(webResource.getSrc());

Easiest way to reload the web resource!

But the same code does not work in case of CRM 2016. As the web resource was already loaded when the page was loaded. CRM 2016 treats the same web resource not to be loaded again (may be for better performance!).

After trying numerous ways to solve, following code worked perfectly:

var webResource = Xrm.Page.getControl("WebResource_ControlName");
webResource.setSrc(Xrm.Page.context.getClientUrl() + "/WebResources/new_webResource?data=someValue%26ver%3D" + Math.random());

Here, I had to pass some parameters. What I have done to modify is added another parameter called “ver” (you can have any other parameter name instead of “ver”) and the value will be rendered from Math.random() method. This way the web browser treats each URL as a new request as Math.random() will return random number each time it will be executed.

CRM 2011: Object address not found on party or party is marked as non-emailable

While sending an Email message from either workflow/plugin or through sdk, if you get this message – “Object address not found on party or party is marked as non-emailable”; check below things:

  1. Check if the record is contact and the records is allowed for Emails or Bulk Email. These are Options available on Contact records and you can set them individually. Make sure both has Allow selected on contact.
  2. Check if your contact records is having a valid email address and not having blank value.

Happy Troubleshooting!!

CRM 2011, JavaScript: Set Customer Type of Lookup

Lets say you have to set Customer type of Lookup from JavaScript. Here is the code! You just have to set another attribute and you’re done!

Here I have given it in parameters as I had to open form with these parameters auto filled.

var params = {};
params["customerid"] = Xrm.Page.getAttribute("customerid").getValue()[0].id;
params["customeridname"] = Xrm.Page.getAttribute("customerid").getValue()[0].name;
params["customeridtype"] = Xrm.Page.getAttribute("customerid").getValue()[0].entityType;

//Open a new account record
Xrm.Utility.openEntityForm("incident", null, params);

Hope it helps!

CRM 2011, JavaScript: How to add some action after save record?

Hi there!

I recently had a requirement where I had to save the record and open another form once the button is pressed from ribbon.

I added the save JavaScript to the web resource and call it and call other function to open the form. This was not working for me.

Resolution for this:

Add an event on Save action by:

Xrm.Page.data.entity.addOnSave(openAccountForm); // openAccountForm is another function which opens the form
Xrm.Page.data.entity.save();
function openAccountForm() {
    Xrm.Utility.openEntityForm("account");
}

CRM 4.0: Create Dynamic Menu Items

We had a requirements to add Dynamic Menu Items to CRM 4.0 Toolbar. I have followed following blog post by Sonoma Partners for implementing Dynamic Menu Items. I have modified their code with simple JavaScript DOM.

http://blog.sonomapartners.com/2009/12/adding-dynamic-menu-items.html

You can follow above mentioned link to create a stub for the implementation and then refer below mentioned code which uses JavaScript DOM and not JQuery to create them.

function createLinksMenu() {

    var links = getCallLinks();
    var dummyElement;

    var ul = document.getElementById("mnuNew_0_CallCustomer");
    var items = ul.getElementsByTagName("li");
    for (var i = 0; i < items.length; ++i) {
        // do something with items[i], which is a <li> element
        if (items[i].innerHTML.indexOf("Dummy") > 0) {
            dummyElement = items[i].cloneNode(true);
            break;
        }
    }

    // Loop through all the links 
    //   then clone the dummy node, update it as necessary and append it to the menu
    for (var i = 0; i < links.length; i++) {
        //alert(links[i].Name);

        var elem = document.getElementById("mnuNew_0_CallCustomer");
        var newEle = dummyElement.cloneNode(true);
        newEle.id = "CallCustomerMenu" + i;
        newEle.className = "ms-crm-MenuItem-Label";
        newEle.tabIndex = -1;
        newEle.action = "callNumber('" + links[i].Url + "');";
        newEle.innerHTML = "<SPAN class='ms-crm-MenuItem-Label'><A class='ms-crm-MenuLink' tabIndex='-1' onclick='return false;' href='javascript:onclick();' target='_self'><SPAN class='ms-crm-MenuItem-Icon'></SPAN><SPAN class='ms-crm-MenuItem-Text' tabIndex='0'>" + links[i].Name + "</SPAN></A></SPAN>";
        elem.appendChild(newEle);
    }

    // remove dummy node
    items = ul.getElementsByTagName("li");
    for (var i = 0; i < items.length; i++) {
        //alert(items[i].innerHTML.indexOf("Dummy"));

        // do something with items[i], which is a <li> element
        if (items[i].innerHTML.indexOf("Dummy") > 0) {
            items[i].style.display = "none";
            break;
        }
    }
}

CRM 2011: Could not load type ‘System.ServiceModel.Activation.HttpModule’

When you try to access the Microsoft Dynamics CRM 2011 Web client, you get the following error.

Could not load type ‘System.ServiceModel.Activation.HttpModule’ from assembly ‘System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

This error can occur when there are multiple versions of the .NET Framework on the computer that is running IIS, and IIS was installed after .NET Framework 4.0 or before the Service Model in Windows Communication Foundation was registered.

Resolution:

1. Go to computer where CRM 2011 is installed and open command prompt.

2. Change the directory to C:\windows\Microsoft.NET\Framework64\v4.0.30319

3. Type the following command-     aspnet_regiis.exe -iru

4. Reset the IIS by iisreset command.

Done! 🙂

CRM 2011, C#, v3.5: Type ‘OptionSetValue’ with data contract name ‘OptionSetValue:http://schemas.microsoft.com/xrm/2011/Contracts’ is not expected

We already have discussed how to achieve connection of CRM 2011 through .net version 3.5 from below mentioned post. https://consultrikin.wordpress.com/2013/09/20/crm-2011-c-entity-class-redefined-with-net-framwork-3-5-to-connect-crm-2011/

Once this is achieved and you start working on CRUD operations, you will find some run time exceptions thrown like one I have described below.

Type ‘OptionSetValue’ with data contract name ‘OptionSetValue:http://schemas.microsoft.com/xrm/2011/Contracts&#8217; is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types – for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.’.  Please see InnerException for more details.

The same thing will be repeated for EntityReference and PicklistAttributeMetadata.

Resolution:

1. Explore the reference.cs from the project in Windows Explorer and open it.

2. Search for class Entity and class EntityReference

3. Add below lines to both partial classes.
     [System.Runtime.Serialization.KnownTypeAttribute(typeof(OptionSetValue))]
     [System.Runtime.Serialization.KnownTypeAttribute(typeof(EntityReference))]

4. Now search for “class OrganizationRequest”.
Add these lines above it:

     [System.Runtime.Serialization.KnownTypeAttribute(typeof(EntityReference))]
     [System.Runtime.Serialization.KnownTypeAttribute(typeof(PrincipalAccess))]
     [System.Runtime.Serialization.KnownTypeAttribute(typeof(OptionSetValue))]

5. Continue adding to classes for which you’re getting these exceptions.

6. Build the solution and run your code again.

Happy Programming! 🙂

CRM 2011, C#: OrganizationRequest and OrganizationResponse with .Net version 3.5

We already discussed how a CRM 2011 web service can help us create object of OrganizationServiceProxy or Instance of IOrganizationService in my previous posts. This is the case when we’re not using assemblies from SDK and thus several SDK request and response messages will not be available to you like RetrieveAttributeRequest/Response etc.

All we have is OrganizationRequest and OrganizationResponse and in this case you will have to use OrganizationRequest and OrganizationResponse to request data from CRM 2011. See below example which uses similar example for RetrieveAttributeRequest.

OrganizationRequest request = new OrganizationRequest();
request.RequestName = "RetrieveAttribute";
request.Parameters = new ParameterCollection();
request.Parameters.Add(new KeyValuePair<string, object>("EntityLogicalName", "salesorder"));
request.Parameters.Add(new KeyValuePair<string, object>("RetrieveAsIfPublished", true));
request.Parameters.Add(new KeyValuePair<string, object>("LogicalName", "new_cardtype"));

try
{
    OrganizationResponse response = (OrganizationResponse)CrmHelper.OrgService.Execute(request);
    PicklistAttributeMetadata picklist = (PicklistAttributeMetadata)response.Results[0].Value;
}
catch (FaultException<OrganizationServiceFault> ex)
{
    throw new Exception("Error details: " + ex.Message);
}

Happy Programming!