tags:

views:

18

answers:

2

When setting a Lookup value in CRM everything works fine if you don't want to change anything, or if you want to set it to a new value. However, when you want to UNSET the current value, the way to do so is unclear.

For example,

house.new_associatepastorid = new HLCImport.CrmSdk.Lookup();
house.new_associatepastorid.type = EntityName.contact.ToString();
house.new_associatepastorid.value = Guid.Empty;

Does not work.

A: 

I found the answer in the SDK. You have to set the isnull value = true, as well as set the isnullspecified = true. You also need to not set the type or the value fields. So the code would be:

house.new_associatepastorid = new HLCImport.CrmSdk.Lookup();
house.new_associatepastorid.IsNullSpecified = true;
house.new_associatepastorid.IsNull = true;
Jeff Davis
A: 

Setting the IsNull and IsNullSpecified properties is absolutely fine. For simpler code, all of the standard types has a static member named Null. So in this case you could have used Lookup.Null.

BlackWasp
I read about that in my research but could not find a way to access the Lookup.Null and have it compile. Do you have an example of how that would work?
Jeff Davis