Reputation: 111
Straight to the point, I am trying to make an application so that the user can search through their CRM system without going onto CRM. I have managed to retrieve the record but when i try to put the record into a list using the records attributes I am only recieving the Keys.
Here is the code:
EntityCollection retrieved = _service.RetrieveMultiple(query);
foreach (var c in retrieved.Entities)
{
foreach (KeyValuePair<String, Object> attribute in c.Attributes)
{
lstRecordDetails.Items.Add(string.Format(attribute.Key + ": " + attribute.Value));
}
}
This only displays the recordID and the Record Name, I understand these are both the primary keys oh the record and i know i could use c.Attributes["description"] for the description but is there a way that i can get all the fields from the record and display them in the list?
Edit: Details on the query
QueryByAttribute query = new QueryByAttribute(entity);
query.ColumnSet = new ColumnSet(field);
query.Attributes.AddRange(field);
query.Values.AddRange(selected);
Upvotes: 0
Views: 6213
Reputation: 846
The way you can retrieve all the columns of an entity is
query.ColumnSet = new ColumnSet(true);
However, be careful with this, because query all columns has an impact on the system (you should always retrieve explicitly the columns you need).
Upvotes: 4
Reputation: 22001
RetrieveMultipleRequest retrieve = new RetrieveMultipleRequest();
retrieve.Query = query;
retrieve.ReturnDynamicEntities = true;
retrieved = (RetrieveMultipleResponse)Service.Execute(retrieve);
foreach(var dynEntity in retrieved.BusinessEntityCollection)
{
foreach (var prop in dynEntity.Properties)
{
lstRecordDetails.Items.Add(string.Format("{0}:{1}", prop.Name, prop.Value);
}
}
Upvotes: 0