locked
Null CrmDateTime? RRS feed

  • Question

  • I'm doing some work for a client that has an older version of CRM (3.0 maybe).  I know if 4.0 you can set a CrmDateTime field to null using IsNull and IsNullSpecified.  But in this version those properties don't appear to be available for CrmDateTime.  Am I missing something?  How can I set dates to null?

    Thanks

    Wednesday, June 9, 2010 8:28 PM

Answers

  • For CRM 3.0, the CrmDateTime class has only a Value member, which takes a string.  I believe if you pass it an empty string ("") it will effectively nullify the value.
    Dave Berry
    Wednesday, June 9, 2010 11:05 PM
    Moderator

All replies

  • This is same with CRM 4.0 ...see below ..make sure you are putting the correct name space in class or code file..

     

    CrmDateTime testDateTime = new CrmDateTime();

    testDateTime.IsNull =

    true;

    testDateTime.IsNullSpecified =

    true;

    Wednesday, June 9, 2010 9:37 PM
  • For CRM 3.0, the CrmDateTime class has only a Value member, which takes a string.  I believe if you pass it an empty string ("") it will effectively nullify the value.
    Dave Berry
    Wednesday, June 9, 2010 11:05 PM
    Moderator
  • Hi,

    David is right,  you have  to  set it  to string.Empty to make it Null.

    As Per SDK, IsNull & IsNullSpecified weren't there for MS CRM 3.0,  Kind of Strange.

    http://msdn.microsoft.com/en-us/library/aa613542.aspx

    where as the same exits for MS CRM 4.0

    http://msdn.microsoft.com/en-us/library/bb930191.aspx

    So as explained  by David and  in below  thread, you have to use String.Empty.

    http://www.eggheadcafe.com/software/aspnet/30189884/setting-a-stringproperty.aspx

    Well to  Add to Suprise, MS CRM 3.0 Sdk also give examples of setting it to Null (using IsNull & IsNullSpecified)

    http://msdn.microsoft.com/en-us/library/aa685869.aspx

    So  My Consulsion  For  CRM 3.0

    All Other Classes (CrmBoolean, Picklist etc except CrmDateTime) has IsNull & IsNullSpecified Property which can  be used  in MS CRM 3.0 to set to Null  Values.

    MS CRM  3.0 Assigning Null Values

    When you update an entity instance there is a mechanism in place to differentiate the absence of a value from a null value. To set an attribute value to null you must set both IsNull and IsNullSpecified to True. For attributes of type String, you must assign the value to String.Empty.


    Muhammad Ali Khan
    http://malikhan.wordpress.com
    • Edited by Muhammad Ali Khan Thursday, June 10, 2010 1:50 AM more info added
    • Proposed as answer by Hanno Z Thursday, June 10, 2010 9:36 AM
    Thursday, June 10, 2010 1:42 AM