Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find out the names of all the attributes in an entity returned from CRM Dynamics

I got myself into the server and I have retrieved (hopefully) the correct set of data. Then, I tried to list all the companies by the following code.

EntityCollection result = proxy.RetrieveMultiple(expression);
foreach (var entity in result.Entities)
{
  String output = String.Empty;
  if (entity.Attributes.Contains("account"))
    output = entity.Attributes["account"].ToString();
}

However, it'd be nice to run an inner loop that goes through all the available attributes in result.Entities. Should I use entity.Attributes.Keys or is there a better method?

like image 627
Konrad Viltersten Avatar asked Sep 13 '12 09:09

Konrad Viltersten


People also ask

What is lookup field in Dynamics CRM?

With lookup fields, you can define views that display different sets of values from the associated entity. So the options a user sees on one form using the lookup could be different from the options a user sees for the same lookup on another form by using different filtered views.

How many types of entities are available in CRM?

There are four different types of entity ownership.

How do I create a lookup view in Dynamics CRM?

You can go into the default Lookup View for the table and do a "Save As" to create a custom Lookup view and then utilize this one instead of the default with the columns you would like (the first two in the view will show in that lookup field). You can set this as the default view for that lookup field on the form.


1 Answers

I think this should do the trick.

foreach (Entity entity in result.Entities)
{
    foreach (KeyValuePair<String, Object> attribute in entity.Attributes)
    {
        Console.WriteLine(attribute.Key + ": " + attribute.Value);
    }
} 
like image 103
James Wood Avatar answered Sep 19 '22 18:09

James Wood