locked
CRM 2015 - can´t create a product via SDK - ProductCreateUpdateEventHandler RRS feed

  • Question

  • Hi there,

    When I use the SDK with the following code I can´t seem to be able to create a product. The code works on both CRM 2011 and 2013. Has anything changed to products in CRM2015 which is causing this or do I need to add more properties to the entity?

    Entity product = new Entity("product");
    product["productnumber"] = "123456789";
    product["defaultuomscheduleid"] = new EntityReference("uomschedule", new Guid("EXACT_GUID"));
    product["defaultuomid"] = new EntityReference("uom", new Guid("EXACT_GUID"));

    service.Create(product);

    => 
    [System.ServiceModel.FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault>] = {"Unexpected exception from plug-in (Execute): Microsoft.Dynamics.Integration.Adapters.Crm2011.Plugin.ProductCreateUpdateEventHandler: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary."}

    I´ve even added this to the product

    product["quantitydecimal"] = 0;
    product["pricelevelid"] = new EntityReference("pricelevel", new Guid("EXACT_GUID"));

    Without much luck.

    So please help :-)

    Tuesday, April 14, 2015 5:40 PM

All replies

  • Hello,

    Provided text of error means that you have plugin that handles creation/update of products and code of this plugin fails because you don't populate some field (my assumption). So you have 2 ways:

    1. Disable plugin.

    2. Get source code of plugin and troubleshoot it.


    Dynamics CRM MVP
    My blog

    Wednesday, April 15, 2015 5:53 AM
    Moderator
  • Hello,

    Don't know this has anything to do with the exception but I checked the system and application required attributes for CRM 2011/2013/2015 as it worked in 2011 and 2013. In 2015 there is a new required attribute: ProductStructure (an optionset).

    Kind Regards and hope this fixes your problem.

    J


    • Edited by Jochen- Wednesday, April 15, 2015 8:10 AM wrong crm environment
    Wednesday, April 15, 2015 8:10 AM
  • This is a system plugin so no source code there.

    Jochen: Thanks for the productstructure hint but it didn´t work either I even tried the following I found at Microsoft:
    https://msdn.microsoft.com/en-us/library/dn817858.aspx

    The following code didn´t work either:
    Product newProductFamily = new Product
    {
    Name = "Example Product Family",
    ProductNumber = "PF001",
    ProductStructure = new OptionSetValue(2)
    };

    _serviceProxy.Create(newProductFamily);

    Get the same error there. When I try and create a Family Product in the UI, I receive the same plugin error but I´m able to create a product there.

    I noticed that the environment I´m using is CRM 2015 RTM (7.0.0.3543), Microsoft just released Update 0.1 (7.0.1.129) - https://support.microsoft.com/en-us/kb/3010990/

    I´m gonna upgrade today/tomorrow and hopefully this "bug" will vanish.

    Regards,
    Ragnar


    Wednesday, April 15, 2015 10:14 AM
  • Raggoz,

    Isn't it possible there is another plugin on your create product? Update your plugin step to asynchronous, check your system job and follow the plugin trace.

    Kind Regards

    Wednesday, April 15, 2015 10:54 AM
  • Hi again,

    Yes it´s definitely Dynamics Connector plugin which is stopping this. Guess some bug there although I have the latest release. When I change the step to async the creation runs through but still have the same error in system job. I´ll report this to the Dynamics Connector forum.

    Thanks

    • Edited by Raggoz Wednesday, April 15, 2015 7:46 PM
    Wednesday, April 15, 2015 12:25 PM