Warm tip: This article is reproduced from serverfault.com, please click

c#-组织服务创建实体返回“缺少单位 ID”

(c# - Organization Service Create Entity returns "The unit id is missing")

发布于 2015-06-30 14:26:27

我有一个 Silverlight 应用程序,我将它用作 CRM 2015 的网络资源,我使用教程来使用 async 和 await 关键字。我可以成功检索实体。但是,我正在尝试将实体创建到 CRM 中,但由于某种原因,我收到错误消息“缺少单元 ID”。

我尝试了一个非常简单的实体创建只是为了测试,但结果仍然相同,这是我的代码:

 Guid ProductCategoryGuid = new Guid(mytextblock.Tag.ToString());
                Money Amount= new Money();
                Amount.Value = Decimal.Parse(mytextblock.Text);

                EntityReference Opportunity = new EntityReference();
                Opportunity.Id = OpportunityGuid;
                Opportunity.LogicalName = "opportunity";

                EntityReference Product = new EntityReference();
                Product.Id = SelectedProductGuid;
                Product.LogicalName = "product";

                EntityReference ProductCategory = new EntityReference();
                ProductCategory.Id = ProductCategoryGuid;
                ProductCategory.LogicalName = "new_productcategory";

                Entity OpportunityProduct = new Entity();
                OpportunityProduct.LogicalName = "opportunityproduct";

                OpportunityProduct["new_productcategory"] = ProductCategory;
                OpportunityProduct["productid"] = Product;
                OpportunityProduct["opportunityid"] = Opportunity;
                OpportunityProduct["baseamount"] = Amount;

                await service.Create(OpportunityProduct);

编辑:

我不确定这是否有帮助,但我使用 Fiddler 调试我的应用程序,但出现此错误:“缺少单元 ID ”。

Questioner
user3340627
Viewed
0
user3340627 2015-07-01 16:49:14

结果我没有为机会产品添加 uom id。我在 OpportunityProduct 中检索到我所指产品的 defaultuomid,然后创建成功完成