web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

ColumnSet Problem with CRM Null Value Custom Fields

(0) ShareShare
ReportReport
Posted on by 110

Hello,

I have one particular custom field I created on CRM that I could not retrieve by ColumnSet. I read that a column could not be retrieved if it had null values. Is there a workaround to retrieve all the custom values on CRM including those fields that have null values?

Here is the portion of the code where I tried in order to retrieve the custom field "new_PrimaryContacthasEmail". I am using early bound:

// Retrieve record of primary contact
Guid primaryContactId = retrievedAccount.PrimaryContactId.Id;
ColumnSet contactCols = new ColumnSet(true);
Contact retrievedContact = (Contact)service.Retrieve("contact", primaryContactId, contactCols);
try
{

if (retrievedContact.EMailAddress1.CompareTo(string.Empty) == 0)
{
retrievedIncident.new_PrimaryContacthasEmail = false;
}
else
{
retrievedIncident.new_PrimaryContacthasEmail = true;
}

service.Update(retrievedIncident);
}
catch (Exception e)
{
Console.WriteLine("An error occurred: '{0}'", e);
}

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Bhaargavi Bodapati Profile Picture
    115 on at

    Hi Ashraf,

    You could try entering name of the field as a string instead of using the early binding.

    Contact retrievedContact = (Contact)service.Retrieve("contact", primaryContactId, new ColumnSet(<fieldName>));

  • David Jennaway Profile Picture
    14,065 on at

    There is no way to get CRM to retrieve columns if they have a null value; this is just the way CRM works. You can query the CRM metadata if you need to identify all columns, but the early-bound process does this for you anyway

  • Community Member Profile Picture
    on at

    Please try as follows:

    Guid primaryContactId = retrievedAccount.PrimaryContactId.Id;
    ColumnSet contactCols = new ColumnSet(true);
    Entity retrievedContact = service.Retrieve("contact", primaryContactId, contactCols);
    try
    {
        if (!retrievedContact.Attributes.Contains("emailaddress1"))
        {
            retrievedIncident.new_PrimaryContacthasEmail = false;
        }
        else
        {
            retrievedIncident.new_PrimaryContacthasEmail = true;
        }
        service.Update(retrievedIncident);
    }
    catch (Exception e)
    {
        Console.WriteLine("An error occurred: '{0}'", e);
    }

    Please let us know.

    If you found the answer helpful, please mark as Verified 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna, ITALY

    Independent Contractor

    http://www.francescopicchi.com

  • Ashraf Abu-Abdou Profile Picture
    110 on at

    Hi Bhaargavi,

    The problem remains. The field could not be retrieved. I could retrieve other custom fields but not this one: "new_PrimaryContacthasEmail"

  • Ashraf Abu-Abdou Profile Picture
    110 on at

    Hi Francesco,

    I still get the error with "new_PrimaryContacthasEmail" despite it is created and published on CRM

  • Community Member Profile Picture
    on at

    Hi Ashraf,

    you need to update reference to crm service each time you add/remove an entity/attribute, please refer to following page:

    https://msdn.microsoft.com/en-us/library/gg327844.aspx 

    Hope it helps.

    Please let us know.

    If you found the answer helpful, please mark as Verified 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna, ITALY

    Independent Contractor

    http://www.francescopicchi.com

  • Ashraf Abu-Abdou Profile Picture
    110 on at

    I run the code generation tool after I add or remove any entity/attribute on CRM. Still the problem remains

  • Ashraf Abu-Abdou Profile Picture
    110 on at

    David,

    So querying CRM metadata has the same outcome as the early bound process when it comes to trying to retrieve null value custom fields?

  • Community Member Profile Picture
    on at

    Please note new_PrimaryContacthasEmail is set, not retrieved, could i miss something?

    Let me know.

  • Ashraf Abu-Abdou Profile Picture
    110 on at

    8004.Untitled.png

    Francesco,

    Kindly refer to the image above. The field could not be found

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans