Hi, may I ask is there any ways that I can fetch entity logicalname by providing the objecttypecode?
Thanks
*This post is locked for comments
Hi, may I ask is there any ways that I can fetch entity logicalname by providing the objecttypecode?
Thanks
*This post is locked for comments
If anyone wants to just pull it with SQL you can grab it from the EntityView view.
SELECT OriginalLocalizedName, LogicalName, ObjectTypeCode FROM [CHANGEME-DB Name].[dbo].[EntityView] ORDER BY OriginalLocalizedName, LogicalName asc
Hi Vivek,
I would recommend to use PowerShell to activate tracing on your server to check and find out what is going wrong.
support.microsoft.com/.../how-to-enable-tracing-in-microsoft-dynamics-crm
If you create a new vanilla organization and open this link, do you also get this error?
Cheers,
Andreas
Hi Andreas,
I am getting following error when I try to access using the https://url/api/data/v8.2/EntityDefinitions
I have dynamic 365 on premises version
{
"error":{
"code":"","message":"An unexpected error occurred.","innererror":{
"message":"An unexpected error occurred.","type":"System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]","stacktrace":" at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.Execute(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType, Boolean checkAdminMode, ExecutionContext executionContext)\r\n at Microsoft.Crm.Extensibility.OData.CrmODataMetadataServiceDataProvider.RetrieveMetadataForEntityType(CrmODataExecutionContext context, Type crmType, EntityQueryExpression entityQuery, String entityId, String crmPropertyName)\r\n at Microsoft.Crm.Extensibility.OData.CrmODataMetadataServiceDataProvider.RetrieveEdmEntityCollection(CrmODataExecutionContext context, String entitySetName, String castEntityName, ODataQueryOptions queryOptions)\r\n at Microsoft.Crm.Extensibility.OData.EntityController.GetEntitySetInternal(String entitySetName, String castEntityName, CrmODataExecutionContext context, CrmEdmEntityObjectCollection crmEdmEntityObjectCollection, ODataQueryOptions queryOptions)\r\n at Microsoft.Crm.Extensibility.OData.EntityController.GetEntitySet(String entitySetName)\r\n at lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
}
}
}
please any help or suggest
Actually you need this:
https://customer.crm.dynamics.com/api/data/v8.1/EntityDefinitions?$select=SchemaName,ObjectTypeCode&$filter=ObjectTypeCode eq 1
results in:
{
"@odata.context":"https://customer.crm.dynamics.com/api/data/v8.1/$metadata#EntityDefinitions(SchemaName,ObjectTypeCode)","value":[
{
"SchemaName":"Account","ObjectTypeCode":1,"MetadataId":"70816501-edb9-4740-a16c-6a5efbc05d84"
}
]
}
https://customer.crm.dynamics.com/api/data/v8.1/EntityDefinitions?$select=ObjectTypeCode&$filter=SchemaName eq 'Account'
will give back the following json result:
{
"@odata.context":"https://customer.crm.dynamics.com/api/data/v8.1/$metadata#EntityDefinitions(ObjectTypeCode)","value":[
{
"ObjectTypeCode":1,"MetadataId":"70816501-edb9-4740-a16c-6a5efbc05d84"
}
]
}
Hi cowboy@arlington,
I found some code from MVP Scott Durow's "SharePoint Integration from CRM Online Workflow/Plugin" which includes methods to fetch entity logical name from ObjectTypeCode.
Original site is here. The purpose of the original code was to parse DynamicUrl to get the Entity Reference.
The class DynamicUrlParser includes Property EntityTypeCode (aka ObjectTypeCode).
public class DynamicUrlParser { public string Url { get; set; } public int? EntityTypeCode { get; set; } public Guid? Id { get; set; } .... }
There's a method in the DynamicUrlParser called GetEntityLogicalName. This method gets the EntityLogicalName from EntityTypeCode.
/// <summary> /// Find the Logical Name from the entity type code - this needs a reference to the Organization Service to look up metadata /// </summary> /// <param name="service"></param> /// <returns></returns> public string GetEntityLogicalName(IOrganizationService service) { var entityFilter = new MetadataFilterExpression(LogicalOperator.And); entityFilter.Conditions.Add(new MetadataConditionExpression("ObjectTypeCode ", MetadataConditionOperator.Equals, this.EntityTypeCode)); var propertyExpression = new MetadataPropertiesExpression { AllProperties = false }; propertyExpression.PropertyNames.Add("LogicalName"); var entityQueryExpression = new EntityQueryExpression() { Criteria = entityFilter, Properties = propertyExpression }; var retrieveMetadataChangesRequest = new RetrieveMetadataChangesRequest() { Query = entityQueryExpression }; var response = (RetrieveMetadataChangesResponse)service.Execute(retrieveMetadataChangesRequest); if (response.EntityMetadata.Count == 1) { return response.EntityMetadata[0].LogicalName; } return null; }
That should do the trick. Hope this helps.
Cheers,
Nadeeja
Hi,
You can use the Metadata Document Generator in XRMToolBox :
This can output the entities of your choice into an Excel document and give you the entity type code and other useful information
Regards
André Arnaud de Cal...
292,489
Super User 2025 Season 1
Martin Dráb
231,305
Most Valuable Professional
nmaenpaa
101,156