Saturday, November 10, 2012

Retrieve Entities Metadata

          Need to retrieve entities metadata information using Silverlight as web resource.

          Sometime you need to know about the entities in the MS CRM 2011 (mean in your organization). What are the properties of the entities such as the schema name, display name, logical name , whether the entity is managed or unmanaged, whether entity is used in the displayed in advance find or not, entity object type code like account has 1 and contact has 2 and so on.For this purpose I have created small application which will list some of the useful properties of the entities. You can see the output in the Image 1 here you can see that I have displayed the display name, name( logical name ), schema name , object type code, state ( where entity is managed or unmanaged), Customizable (Boolean type either true or false) and last one the description of the entity if it is provided.

Image 1
Code is listed in List 1 , here you can see that I have used organization request object and pass the "RetrieveAllEntities" as request name. The "RetrieveAllEntities" request contains the data that is needed to retrieve metadata information about all the entities.Next is to set the "EntityFilters" attribute which take the one of the enumeration value of "EntityFilters".Here you can see that I have used the Entity which is also the default value if you don’t set the entity filter value and it is used to retrieve only entity information.Second and the last parameter which is set for the request object is the "RetrieveAsIfPublished" (Gets or sets whether to retrieve the metadata that has not been published) which take Boolean value and is required parameter. Here I have set it to false.Then created the service object and the used begin execute to past he request object, attached the callback function and also passed service object.
In the callback function you can see that first statement is to end the request which was execute request. And then get the entities from the response object here you can see that "EntityMetadata" is get from the response object.
List 1

Then I have used the foreach loop to loop through each entity and you can see that I have put if condition to filter the only those record which are either custom entity or is customizable. One more condition is check display name of the entity if it is null then continue don’t need to add entity which don’t have display name.And then used the entity properties which I want to display in the data grid control like, logical name, schema name, object type code, is managed, is customization and the description property. You can also use other properties which you want to display in the data grid control based on your requirement. Hope you get idea of how to get the entities metadata using the request object in Silverlight web resource.  

You can download the source code of the sample from here.
and working CRM 2011 solution from here.

Go to Home

All and any comments / bugs / suggestions are welcomed!

No comments: