Search code examples
c#dynamics-crmmicrosoft-dynamicsdynamics-365

C# Dynamics 365: Set lookup value to null or blank


In Dynamics 365 I have an employee (user) that has a reference to his/her manager (another user). I want to programatically clear that value.

This line of code will update to any user that matches the ID. But I am not able to clear the value.

user.Attributes["parentsystemuserid"] = new EntityReference("systemuser", managerId);
service.Update(user);

I have tried things like setting the managerId value to "null", "", and a Guid consisting only of zeroes. I am not able to find many attempts to answers to this online. This here http://ronaldlemmen.blogspot.com/2007/02/set-lookup-to-null.html was my best bet, but as far as I can tell "Entity" does not hold a "Lookup" property, so no luck there either.


Solution

  • This should work.

    user.Attributes["parentsystemuserid"] = null;
    service.Update(user);