Reputation: 1993
I have an entity called NDS which has a look up to account. Now, in the UI, I can click on the Lookup icon and click on another account record (Update) or click on the Remove button to remove the value.
How do I do the same functionality via code for the remove. I am writing a Plugin.
//Code to update
NDS["accountid"] = new EntityReference("Account", neworganizationid);
xrmService.Update(NDS)
//Code to remove
//??
The code to update works fine. It is the code to remove where it fails. I thought that the code to update would just work fine without any issues even with Remove, but I have an error message
Account With Id = 00000000-0000-0000-0000-000000000000 Does Not Exist
Any thoughts?
PS: I am new to MS CRM.
Upvotes: 3
Views: 4254
Reputation: 18895
As long as it's not an N:N relationship, you just need to do this:
NDS["accountid"] = null;
xrmService.Update(NDS);
From your error message I'm guessing you're doing this:
NDS["accountid"] = new EntityReference();
xrmService.Update(NDS);
which won't work.
And as a reminder, if it is an N:N relationship, you'll need to use the Disassociate Request
Upvotes: 3