locked
Setting option set value to null programmatically? RRS feed

  • Question

  • I need to un-set an optionset value using C# for Dynamics CRM 2011. In other words, I'd like to set it to null. How can this be accomplished?

    Thanks.


    • Edited by MeProgrammer Wednesday, April 2, 2014 6:43 PM typo
    Wednesday, April 2, 2014 6:39 PM

All replies

  • How about: 
    //Early bound
    Account a = (Account)_serviceProxy.Retrieve(Account.EntityLogicalName,
    	new Guid("DCC721C7-FDB0-E311-9429-6C3BE5A8FDB8"), new ColumnSet(true));
    a.CustomerTypeCode = null;
    
    //Late bound
    Entity a2 = _serviceProxy.Retrieve("account",
    	new Guid("DCC721C7-FDB0-E311-9429-6C3BE5A8FDB8"), new ColumnSet(true));
    a2["customertypecode"] = null;
    
    _serviceProxy.Update(a);


    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Wednesday, April 2, 2014 7:08 PM
    Moderator
  • just set to null the attribute:

    entity["optionsetfield"] = null;



    My blog: www.crmanswers.net - Rockstar 365 Profile

    Wednesday, April 2, 2014 7:09 PM
  • Thanks, Jason. Sorry for the delay getting back to you. I will try that but the reason why I asked is because I thought there was some complication to just setting it to null.
    Friday, April 4, 2014 9:54 PM