C# 创建产品捆绑动态365 CRM时未设置默认价目表

C# 创建产品捆绑动态365 CRM时未设置默认价目表,c#,dynamics-crm,dynamics-crm-365,dynamics-365-sales,C#,Dynamics Crm,Dynamics Crm 365,Dynamics 365 Sales,我正在尝试为使用Microsoft.CrmSdk.CoreSassemblies创建的产品捆绑包设置默认价目表。我已经编写了工作代码,成功地创建了产品捆绑包,其中包含我在代码中指定的所有配置,但从未设置默认价目表。以下是代码片段: Entity ProductBundleEntity = new Entity("product"); ProductBundleEntity.Attributes["name"] = Nam

我正在尝试为使用Microsoft.CrmSdk.CoreSassemblies创建的产品捆绑包设置默认价目表。我已经编写了工作代码,成功地创建了产品捆绑包,其中包含我在代码中指定的所有配置,但从未设置默认价目表。以下是代码片段:

  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);

请建议我是否遗漏了任何内容。

虽然我不知道PriceListId变量的定义,但通常需要按如下方式分配id,我认为PriceListId变量不包含值

ProductBundleEntity.Attributes[pricelevelid]=new EntityReferencepricelevel,Microsoft.Xrm.Sdk.EntityReferenceoriginalEntity.Attributes[pricelevelid].Id

您是否收到任何错误? 插件何时运行,创建/更新? 它是同步的吗 是手术前还是手术后


如果发布,您可能必须使用service.updateEntity对象,最好尝试预操作,以便可以使用相同的对象。

您是否收到任何错误?你的插件什么时候运行,创建/更新?它是同步的吗?不,它运行时没有任何错误,我正在尝试在创建期间设置它。是的,是同步的。是手术前还是手术后?如果发布,您可能必须使用service.updateEntity对象,最好尝试使用pre操作,以便可以使用相同的对象。我不知道这些操作的“pre”或“post”概念。但正如pre/post的定义所表明的,这似乎是一个预操作,我在其中设置产品包实体的属性pricelevelid,然后调用service.createproductbundleentity。我没有尝试将价目表设置为更新操作。让我试试使用更新操作设置价目表是否有效。“PriceListId”基本上是Dynamics中“UK price list”的GUID,我在调试时检查过,它不是空/不正确的。否则代码在创建实体引用时会抛出一个错误。这个提示实际上是有效的。如果使用service.updateentity操作设置实体,则会为该实体设置默认价目表。