Thursday, May 10, 2012

Retrieve Metadata For All Entities in a Dynamics CRM 2011 Organization Using VB.NET

This illustration shows you how to retrieve metadata for all entities in an organization using VB.NET with the RetrieveAllEntities message against the CRM 2011 organization service.

IMPORTANT NOTE: This call didn't work very well for me as it returns A LOT of data and I couldn't even get it to work against CRM Online using EntityFilters.All.  I am guessing it would time out against on-premise also without some server side timeout tweaking.  Using just EntityFilters.Relationships the call took almost 90 seconds to complete and the resulting return message envelope was OVER 45,000 LINES LONG!
As a result I find that the normal RetrieveEntityRequest is a much more reasonable option and it performs fairly well, but it will only return one entity at a time.

Here is a link to where I cover the RetrieveEntityRequest that I do recommend using:
http://mileyja.blogspot.com/2011/05/how-to-retrieve-metadata-for-entity.html


Ok, anyways, lets look at the RetrieveAllEntitiesRequest Message.
In VB.NET:

Dim req As New RetrieveAllEntitiesRequest()
req.EntityFilters = EntityFilters.Privileges
req.RetrieveAsIfPublished = True
Dim resp As RetrieveAllEntitiesResponse = DirectCast(service.Execute(req), RetrieveAllEntitiesResponse)



It is important to note that you can filter on the type of entity metadata you want returned since the returned XML document will be very large if you choose EntityFilters.All as shown above.  Your choices are All, Attributes, Default, Entity, Privileges, and Relationships.

Thats all there is to it!

I hope this helps!

No comments:

Post a Comment