Hi,
I'm getting an exception on proxy.Create(product) line;
Parameter value cannot be 0
Parameter name: value
uom and uomschedule both exist, even tried to hardcode uom values from existing products, with the same result
here's my code:
try
{
var query = new QueryByAttribute("uom");
query.ColumnSet = new ColumnSet("name", "uomscheduleid");
query.Attributes.AddRange("name");
query.Values.AddRange("SZT");
Entity unit = proxy.RetrieveMultiple(query).Entities[0];
Entity product = new Product()
{
Name = "test product",
ProductNumber = "123test123",
Description = "asdfasdfa",
DefaultUoMScheduleId = (EntityReference)unit.Attributes["uomscheduleid"],
DefaultUoMId = unit.ToEntityReference(),
};
var prod = proxy.Create(product);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
I have a lot of similar creation procedures working for other entities, for a first time I have to create product,
and got stuck
will appreciate any advice,
Kind Regards
I'm glad you were able to resolve your issue.
You were right, there was oncreate plugin from MS Dynamics Connector, fortunatelly we do not use it anymore, after I deactivated a plugin, product has been created :D
thx for help,
Kind Regards
So I have 2 news for you:
1. Good one - there is nothing wrong with your code. Keep using it.
2. Bad one the issue is in Microsoft.Dynamics.Integration.Adapters.Crm2011.Plugin.ProductCreateUpdateEventHandler plugin. The only recommendation that I have - download the assembly that contains that plugin, use ILSpy or .Net Reflector to see the source code, check what is missing in your code or the data inside your system.
got back to simple code, grabbed ids from existing product to be sure,
try
{
Guid UnitGroupId = new Guid("D69877A0-8C48-493A-9CEB-9E40D9377DBC");
Guid unitId = new Guid("D20C830F-E7B6-E511-8B8B-00155D023200");
Guid priceLevelId = new Guid("9B75D209-F94A-E511-BA69-00155D023200");
Entity product = new Entity("product");
product.Attributes["name"] = "Example Product 1";
product.Attributes["productnumber"] = "P001";
product.Attributes["defaultuomscheduleid"] = new EntityReference("uomschedule", UnitGroupId);
product.Attributes["defaultuomid"] = new EntityReference("uom", unitId);
product.Attributes["pricelevelid"] = new EntityReference("pricelevel", priceLevelId);
Guid _product1Id = proxy.Create(product);
}
and I am getting
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.
Daivat Vartak (v-9d...
225
Super User 2025 Season 1
Muhammad Shahzad Sh...
106
Most Valuable Professional
Eugen Podkorytov
87