我希望somone能够进一步帮助我,因为我真的被困在这里。我试图从post-creat插件向我的合同实体添加合同行。我的代码:
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,因为我在另一个实体上的另一个字段上检查它。如果somone可以帮助我,我真的很感激。感谢。
答案 0 :(得分:2)
ContractLine["contractid"]
= c_Id;是ContractLine["contractid"] = new EntityReference("contract", c_Id);
?
c_Id还应该是EntityReference而不是GUID吗?
答案 1 :(得分:1)
你有任何一个机会因你的问题而被解雇,这会引发异常。这似乎总是咬我。尝试禁用除您正在处理的插件之外的所有其他插件......