locked
how to set CrmSdk.CrmDateTime() field to null RRS feed

  • Question

  • i am using below code to set

    CrmSdk.CrmDateTime() to null

    newContact.birthdate = new CrmSdk.CrmDateTime();

    newContact.birthdate.IsNull = true;

    newContact.birthdate.IsNullSpecified = true;

    but it is giving me error

    Server was unable to process request.   0x80040265   Object reference not set to an instance of an object.  

    can any one help me

    Friday, January 15, 2010 6:39 AM

Answers

  • Thanks Muhammad Ali Khan Users MedalsUsers MedalsUsers MedalsUsers Medals and Ranjit

    i found that in the server which i a am getting the error, there was a plug In , and that plug is used for some business rule i.e it was giving the error
      
    • Marked as answer by Micro Max Friday, January 29, 2010 12:34 PM
    Friday, January 29, 2010 12:33 PM

All replies

  • This is the correct method. check this
    http://technet.microsoft.com/en-us/library/bb928938.aspx

    There might be some other problem in your code, may be some other object is null, newContact? or some other?

    Friday, January 15, 2010 6:49 AM
  • I verified evey thing when i comment this

    newContact.birthdate = new CrmSdk.CrmDateTime();

    newContact.birthdate.IsNull = true;

    newContact.birthdate.IsNullSpecified = true

    it is working fine , what could be the problem

    Friday, January 15, 2010 7:10 AM
  • it is strange. are you sure newContact is not null.
    can u debug and catch the SoapExcetion and see what is the message. it will have more details.
    Friday, January 15, 2010 7:16 AM
  • i debuged, same code it is working in one server ,in other server it is not working
    and this error i am getting when i  updated any contact record

    when i comment  these it is working fine


    CrmSdk.CrmDateTime() to null

    newContact.birthdate = new CrmSdk.CrmDateTime();

    newContact.birthdate.IsNull = true;

    newContact.birthdate.IsNullSpecified = true;

    try

    {

    newContact.contactid = new CSSI.VUE.IncentivePoint.CrmSdk.Key();

    newContact.contactid.Value = new Guid(dr["GUID"].ToString());

    insuredDemographicsService.Update(newContact);

    }

    catch (System.Web.Services.Protocols.SoapException ex)

    {

    #region

    Exception Catch block

    string error;

    error = ex.Message + ex.Detail.InnerText;

    error = error.Replace("\n", " ");

    #endregion

    }

    Friday, January 15, 2010 8:52 AM
  • Why you are getting in ex.Detail.InnerText?

    It is very strange :(

    Also in these lines.

    newContact.contactid = new CSSI.VUE.IncentivePoint.CrmSdk.Key();

    newContact.contactid.Value = new Guid(dr["GUID"].ToString());

    insuredDemographicsService.Update(newContact);

    Is Guid of the contact valid? If this is not a Valid Guid (means this contact doesn't exits on the server) then an exception will be thrown in case of hte update method.

    Tthe URL of the crmService is pointing to the right CRM server?

    Try to update some other attribute in the same contact. is hte attribute getting updated?


    Friday, January 15, 2010 10:25 AM
  • Yes if  comment this date related code and updated other attributes it is woking fine and that to it is working in one server and other server it is giving the error
    Friday, January 15, 2010 10:49 AM
  • This seems to very strange. it should not happens. Are you over-looking something?

    means if you comment the code of the date then it working fine on BOTH SERVER???

    can u verify all of these?

    1) getting in ex.Detail.InnerText? THis will give you the exception in more detail?
    2) Is Guid of the contactId Valid? means it exits on teh server
    3) Is URL to the CRMService right?

    I would recommend u  to debug the code and check each value.
    Friday, January 15, 2010 11:23 AM
  • ex.Detail.InnerText  i am getting only this

     error Server was unable to process request.   0x80040265   Object reference not set to an instance of an object.   Platform

    Guid of the contactid is valid , i verified and if i comment birthdate  it is updating the other fields without any error
    CRM web service are pointing to correct Organization , i could see the updated records in CRM

    same code if i use in differnet server  it is setting to null and not giving any error

    CrmSdk.CrmDateTime() to null

    newContact.birthdate = new CrmSdk.CrmDateTime();

    newContact.birthdate.IsNull = true;

    newContact.birthdate.IsNullSpecified = true;

    Friday, January 15, 2010 12:40 PM
  • Hi Faiyaz,

    Use the below code to assign a null value to a CrmDateTime object:

    CrmSdk.CrmDateTime() dtBirthdate = new CrmSdk.CrmDateTime();
    dtBirthdate.IsNull = true;
    dtBirthdate.IsNullSpecified = true;

    newContact.birthdate = dtBirthdate;

    Thanks,


    Thanks, Ranjitsingh R | http://mscrm-developer.blogspot.com/ | MS CRM Consultant
    Saturday, January 16, 2010 3:44 AM
  • Hi Faiyaz,

    Use the below code:

    Lookup Contact = new Lookup();
    Contact.type = "contact";
    Contact.id = new Guid(dr["GUID"].ToString());

    // assign contact lookup object
    newContact.contactid = Contact;
    insuredDemographicsService.Update(newContact);


    Thanks, Ranjitsingh R | http://mscrm-developer.blogspot.com/ | MS CRM Consultant
    Saturday, January 16, 2010 3:47 AM
  • Hi Ranjit,

    I tried this code but still same error

    CrmSdk.CrmDateTime() dtBirthdate = new CrmSdk.CrmDateTime();
    dtBirthdate.IsNull = true;
    dtBirthdate.IsNullSpecified = true;

    newContact.birthdate = dtBirthdate;


    when i use the below code to updated

    Lookup Contact = new Lookup();
    Contact.type = "contact";
    Contact.id = new Guid(dr["GUID"].ToString());

    // assign contact lookup object
    newContact.contactid = Contact;
    insuredDemographicsService.Update(newContact);


    getting the below error

    Error 2 Cannot implicitly convert type 'CrmSdk.Lookup' to 'CrmSdk.Key' 
    Monday, January 18, 2010 9:38 AM
  • Hi Ranjit,

    Error 2 is coming becuase you are not setting up a key for contact.id.
    Check contact.id property what it requires? Accordingly type cast the guid of contact entity.
    Monday, January 18, 2010 11:25 AM
  • Thanks Muhammad Ali Khan Users MedalsUsers MedalsUsers MedalsUsers Medals and Ranjit

    i found that in the server which i a am getting the error, there was a plug In , and that plug is used for some business rule i.e it was giving the error
      
    • Marked as answer by Micro Max Friday, January 29, 2010 12:34 PM
    Friday, January 29, 2010 12:33 PM