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)

CRM Retrievemultiple not returning null columns in the collection

(0) ShareShare
ReportReport
Posted on by 2

Hi all,

below is my code where i'm trying to retrieve a record with all the fields using query expression based on the condition.. the issue is i'm getting only those attributes that contains data in the collection 'ec' where i want all the attributes i.e contains or does not contains data.. please let me know how i can resolve this issue.


QueryExpression queryPrincipal = new QueryExpression("contact");
ColumnSet col = new ColumnSet(true);
queryPrincipal.ColumnSet = col;
queryPrincipal.Criteria.AddCondition("new_customerid", ConditionOperator.Equal, 600);
EntityCollection ec = _serviceProxy.RetrieveMultiple(queryPrincipal);

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    Retrieve and RetrieveMultiple only return non null columns. Why do you need to retrieve null valued columns?

  • Suggested answer
    Rawish Kumar Profile Picture
    13,758 on at

    Hi Puneeth,

    Nothing wrong with your query - its by design that CRM will not return columns if they are null.

    you will have to check for individual columns like ec.Contains("columnName") which will return true or false.

  • Puneeth Profile Picture
    2 on at

    Thanks for the reply..

    I have a requirement where i'm implementing WCF service in that service i'm defining all the columns in the account entity and i'm updating it into SQL DB of other VB .net application.. but those fields which is null is not being retrieved and i'm getting 'key not found exception' where i just want the null columns to update as null in SQL DB..

    I can perform validation for each column 'if attribute key contains in the collection then update DB else null' but i'm having 100 fields to update in DB where i have to put this validation for each columns....

    which isn't good program practice..

    Any help would be appreciable .. Thanks.  

  • Puneeth Profile Picture
    2 on at

    Thanks for the reply..

    I have a requirement where i'm implementing WCF service in that service i'm defining all the columns in the account entity and i'm updating it into SQL DB of other VB .net application.. but those fields which is null is not being retrieved and i'm getting 'key not found exception' where i just want the null columns to update as null in SQL DB..

    I can perform validation for each column 'if attribute key contains in the collection then update DB else null' but i'm having 100 fields to update in DB where i have to put this validation for each columns....

    which isn't good program practice..

    Any help would be appreciable .. Thanks.  

  • Suggested answer
    Jakob Nilsson Profile Picture
    2 on at
    I'm guessing that this has been resolved by the thread author a long time ago, but on the off-chance that anyone stumbles upon the same problem, as I did recently, here is my solution:

    Given that the entity returned is lacking the columns with null values, we need to extract which columns these are without having them actually being returned. I found the solution in extracting the difference between the columns in the request (the ColumnSet used in the QueryExpression) and the attributes assigned to each entity.
    Then, I added the missing columns by using entity.Attributes.Add([the missing column], null) via an iterator for the collection making up the difference between requested columns and returned columns.
     
    For me, it looked something like this:
     
    var nullColumns = columnSet.Columns.Except(entity.Attributes.Keys);
    if (nullColumns != null)
    {
        foreach (var column in nullColumns)
        {
             entity.Attributes.Add(column, null);
        }
    }



    This is done after the query is run, and is iterated for each entity in the RetrieveMultiple response.
     
    I hope this can be of help to anyone!

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