Reputation: 1467
I am trying to set default price list for a product bundle that i am trying to create using Microsoft.CrmSdk.CoreAssemblies
. I have written the working code that successfully creates the product bundle with all the configurations that I specify in the code but default price list is never set. Following is the code snippet:
Entity ProductBundleEntity = new Entity("product");
ProductBundleEntity.Attributes["name"] = Name;
ProductBundleEntity.Attributes["productstructure"] = new OptionSetValue(3);
ProductBundleEntity.Attributes["productnumber"] = Guid.NewGuid().ToString();
///// setting defult price list here
ProductBundleEntity.Attributes["pricelevelid"] = new EntityReference("pricelevel", PriceListID);
ProductBundleEntity.Attributes["defaultuomscheduleid"] = new EntityReference("uomschedule", UOMScheduleID);
ProductBundleEntity.Attributes["defaultuomid"] = new EntityReference("uom", UOMID);
Please suggest if i am missing anything.
Upvotes: 0
Views: 692
Reputation: 5531
Did you receive any error? When is your plugin running, create/update? Is it synchronous? – is it pre operation or post?
If post you might have to use service.update(Entity object) Better try with pre operation so that same object/ can be used.
Upvotes: 1
Reputation: 11
Although I don't know the definition of the PriceListId variable, normally you need to assign an id as below, I think the PriceListId variable does not contain a value;
ProductBundleEntity.Attributes["pricelevelid"] = new EntityReference("pricelevel", ((Microsoft.Xrm.Sdk.EntityReference)(originalEntity.Attributes["pricelevelid"])).Id);
Upvotes: 0