Occasionally you may come across the need to return all of the attributes on an entity. Today I’m going to show you how to return all attributes inside of Fetch, within the IOrganizationService, and provide a little caution about returning all attributes.
This is pretty well documented, but it’s worth mentioning. In FetchXML, you’ll simply use “<all-attributes />”:
<fetch mapping='logical' page='1' count='10'>
<link-entity name='systemuser' to='createdby'>
<condition attribute='firstname' operator='eq' value='Jeff' />
<condition attribute='lastname' operator='eq' value='Smith' />
<condition attribute='createdon' operator='today' />
This query returns all of the accounts that Jeff Smith created today. In this example the “<all-attributes />” only applies to the account entity and does not return all of the attributes of the linked entity.
When it comes to the IOrganizationService, I couldn’t find any examples of this but was able to figure it out from the SDK. Here it is simply:
ColumnSet csAll = new ColumnSet(true);
Entity retEnt = (Entity)_service.Retrieve(sLogicalName, gEntity, csAll);
The trick here is that we need to build our ColumnSet with a Boolean value of true.
When to Use ALL
First off, it should be rare in production code. The reason you want to typically avoid returning all of the attributes is because it will be slower if you aren’t using but a few of the attributes. Typically you will specify what attributes you need or tie into a CRM View (which allows the user to easily change what records are displayed).
Sometimes though, you may need to provide flexibility in lieu of a slight performance hit. I came across the need for returning all of the attributes due to a customer portal where I am dynamically displaying an entity and allowing the user to update the entity. Using all attributes, I can allow the Portal form to be customizable as well as allowing for any entity.
Post by: Paul Way,