Wednesday, July 8, 2009

Get Entity Type Name - server side

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

int entityTypeCode = 2;
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.ObjectTypeCode.Value == entityTypeCode)
return meta.LogicalName;
}

Enjoy,
Rami Heleg