Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 79901

How to get the entity logical name of an entity in CRM by URL ?

$
0
0

In a workflow step in CRM 2011, I must get the entity logical name of the record using URL of that record.

I get the GUID from url and then i used this method to get the logical name:

RetrieveAllEntitiesRequest allEntitiesRequest = new RetrieveAllEntitiesRequest();
allEntitiesRequest.EntityFilters = EntityFilters.Entity;
allEntitiesRequest.RetrieveAsIfPublished = true;
RetrieveAllEntitiesResponse allEntitiesResponse = (RetrieveAllEntitiesResponse)IOrgService.Execute(allEntitiesRequest);



string entityLogicalName = string.Empty;
foreach (EntityMetadata entityMetadata in allEntitiesResponse.EntityMetadata)
{
try
{
// Try to retrieve the record from the current entity
Entity test = IOrgService.Retrieve(entityMetadata.LogicalName, objectguid, new Microsoft.Xrm.Sdk.Query.ColumnSet(true));
// if the previous instruction didn't throw an exception means that the record exists.
entityLogicalName = entityMetadata.LogicalName;
break;
}
catch
{

}
}

But, this method has overload of loading and retrieving, and in case of actitvities has some bugs. 

what is better solution to this problem?


Viewing all articles
Browse latest Browse all 79901

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>