locked
NULL values in some fields in ContactBase table, a couple of question please? RRS feed

  • Question

  • I have a for loop that selects some fields using RetrieveMultiple service method, like below:

    QueryExpression query2 = new QueryExpression("contact"); query2.ColumnSet.AddColumns("address1_line1"); query2.ColumnSet.AddColumns("address1_line2"); query2.ColumnSet.AddColumns("address1_freighttermscode"); query2.ColumnSet.AddColumns("mobilephone"); query2.ColumnSet.AddColumns("emailaddress1"); var x2 = _orgService.RetrieveMultiple(query2); foreach (var entityItem in x2.Entities) { Entity testAccount = entityItem; ...code here to pass testAccount variable variable to another method to process the row... }

    Then I compare the fields of "entityItem" specifically "firstname" and "lastname" to another collection from my own table.

    The problem is some fields in CRM have null values.

    1) if a field has a null value, will it totally remove the attribute from the properties of the row? So the above code,

    if the "mobilephone" is NULL, will the attribute "mobilephone" be removed by the service method in the attribute list?

    2) how do i handle the null when trying to access the field like this

    testAccount.Attributes["mobilephone"].ToString()

    without doing this?

    var temp = testAccount.Attributes["mobilephone"].ToString() ? String.Empty : testAccount.Attributes["mobilephone"].ToString()

    Thursday, March 27, 2014 7:59 AM

Answers

  • Hi

    Try

    var mobilePhone =  testAccount.Attributes.Contains("mobilephone") ? testAccount.Attributes["mobilephone"]  : String.Empty ;



    Zafar Khan

    • Marked as answer by LayneDad Tuesday, April 1, 2014 7:23 AM
    Thursday, March 27, 2014 8:11 AM

All replies

  • Hi

    Try

    var mobilePhone =  testAccount.Attributes.Contains("mobilephone") ? testAccount.Attributes["mobilephone"]  : String.Empty ;



    Zafar Khan

    • Marked as answer by LayneDad Tuesday, April 1, 2014 7:23 AM
    Thursday, March 27, 2014 8:11 AM
  • cheers brother
    Tuesday, April 1, 2014 7:23 AM