2

我希望有人能进一步帮助我,因为我真的很困在这里。我试图从创建后插件向我的合同实体添加合同行。我的代码:

Guid c_Id = (Guid)entity.Attributes["contractid"];
DateTime start = (DateTime)entity["activeon"];
DateTime end = (DateTime)entity["expireson"];
Money money = new Money();
money.Value = 0;


//Set Instance for Contract Line 
Entity ContractLine = new Entity();
ContractLine.LogicalName = "contractdetail";

//Create Contract Line for the Contract
ContractLine["title"] = "PLUGIN FIRED";
ContractLine["activeon"] = start;
ContractLine["expireson"] = end;
ContractLine["totalallotments"] = 1;
//ContractLine["customerid"] = entity["customerid"];  
//ContractLine["productid"] = entity["productid"];
ContractLine["price"] = money;
ContractLine["contractid"] = c_Id;

service.Create(ContractLine);

出于某种原因,我收到“属性:contractid 不能设置为 NULL”的错误,这真的很奇怪,因为它实际上确实获得了 contractid 的 GUID,因为我在另一个实体的另一个字段上检查了它。如果有人能在这里帮助我,我将不胜感激。谢谢。

4

2 回答 2

2

应该ContractLine["contractid"]= c_Id; 是ContractLine["contractid"] = new EntityReference("contract", c_Id);吗?

c_Id 也应该是 EntityReference 而不是 GUID?

于 2012-05-23T16:10:25.400 回答
1

任何机会你有另一个插件因为你的抛出异常而被触发。这似乎总是在咬我。尝试禁用除您正在使用的插件之外的所有其他插件...

于 2012-05-23T15:35:02.943 回答