Reputation: 309
I hope somone can help me further, as I'm really much stuck here. Im trying to add a contract line to my contract entity from a post-creat plugin. My code:
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);
For some reason I get the error that "Attribute: contractid cannot be set to NULL" which really stragnge because it actually does get the GUID for the contractid, as I checkd it on another field on another entity. I would really much appreciate if somone can help me out here. Thanks.
Upvotes: 2
Views: 1026
Reputation: 4085
Should ContractLine["contractid"]
= c_Id; be ContractLine["contractid"] = new EntityReference("contract", c_Id);
?
Also should c_Id be an EntityReference instead of a GUID?
Upvotes: 2
Reputation: 18895
Any chance you have another plugin that is firing as a result of yours that is throwing the exception. That always seems to bite me. Try disabling all other plugins except for the one you're working on...
Upvotes: 1