Wednesday, July 8, 2009

Get Entity Type Code - server side

Getting entity type code via metadata service
an Example for CRM 4.0

string entityTypeName = "contact";
RetrieveAllEntitiesRequest request = new RetrieveAllEntitiesRequest();
request.MetadataItems = MetadataItems.EntitiesOnly;
RetrieveAllEntitiesResponse response = (RetrieveAllEntitiesResponse)metadataService.Execute(request);
CrmMetadata[] Metadata = response.CrmMetadata;
foreach (EntityMetadata meta in Metadata) {
if (meta.LogicalName == entityTypeName)
return meta.LogicalName;
}

Enjoy,
Rami Heleg