So here is the code to do the same:
public static string geEntityLogicalName(int ObjectTypeCode)
{
string entityLogicalName = String.Empty;
MetadataFilterExpression EntityFilter =
new MetadataFilterExpression(LogicalOperator.And);
EntityFilter.Conditions.Add(new MetadataConditionExpression
(\"ObjectTypeCode\", MetadataConditionOperator.Equals, ObjectTypeCode));
MetadataPropertiesExpression mpe = new MetadataPropertiesExpression();
mpe.AllProperties = false;
mpe.PropertyNames.Add(\"ObjectTypeCode\");
EntityQueryExpression entityQueryExpression = new EntityQueryExpression()
{
Criteria = EntityFilter,
Properties = mpe
};
RetrieveMetadataChangesResponse initialRequest =
GetMetadataChanges(entityQueryExpression, null, DeletedMetadataFilters.OptionSet);
if (initialRequest.EntityMetadata.Count == 1)
{
entityLogicalName = initialRequest.EntityMetadata[0].LogicalName;
}
return entityLogicalName;
}
protected static RetrieveMetadataChangesResponse GetMetadataChanges
(EntityQueryExpression entityQueryExpression, String clientVersionStamp, DeletedMetadataFilters deletedMetadataFilter)
{
RetrieveMetadataChangesRequest retrieveMetadataChangesRequest =
new RetrieveMetadataChangesRequest();
{
Query = entityQueryExpression,
ClientVersionStamp = clientVersionStamp,
DeletedMetadataFilters = deletedMetadataFilter
};
return (RetrieveMetadataChangesResponse)service.Execute(retrieveMetadataChangesRequest);
}
Dynamics 365 Entity Object Type Code List:
Complete Code:
using Microsoft.Xrm.Sdk;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Crm.Sdk.Messages;
using System.ServiceModel.Description;
using System.Net;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Metadata.Query;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Metadata;
namespace CRMCodeHelper
{
class Program
{
private static IOrganizationService service = null;
static void Main(string[] args)
{
service = ConnectToCRM();
string entityLogicalName = geEntityLogicalName(112);
Console.WriteLine(\"Entity Logical Name is: \" + entityLogicalName);
Console.ReadLine();
} public static string geEntityLogicalName(int ObjectTypeCode) { string entityLogicalName = String.Empty; MetadataFilterExpression EntityFilter =
new MetadataFilterExpression(LogicalOperator.And);
EntityFilter.Conditions.Add(new MetadataConditionExpression(\"ObjectTypeCode\", MetadataConditionOperator.Equals, ObjectTypeCode));
MetadataPropertiesExpression mpe = new MetadataPropertiesExpression();
mpe.AllProperties = false;
mpe.PropertyNames.Add(\"ObjectTypeCode\");
EntityQueryExpression entityQueryExpression = new EntityQueryExpression()
{
Criteria = EntityFilter,
Properties = mpe
};
RetrieveMetadataChangesResponse initialRequest =GetMetadataChanges(entityQueryExpression, null, DeletedMetadataFilters.OptionSet);
if (initialRequest.EntityMetadata.Count == 1)
{
entityLogicalName = initialRequest.EntityMetadata[0].LogicalName;
}
return entityLogicalName;
}
protected static RetrieveMetadataChangesResponse GetMetadataChanges(EntityQueryExpression entityQueryExpression, String clientVersionStamp, DeletedMetadataFilters deletedMetadataFilter)
{
RetrieveMetadataChangesRequest retrieveMetadataChangesRequest =new RetrieveMetadataChangesRequest()
{
Query = entityQueryExpression,
ClientVersionStamp = clientVersionStamp,
DeletedMetadataFilters = deletedMetadataFilter
};
return (RetrieveMetadataChangesResponse)service.Execute(retrieveMetadataChangesRequest);
}
public static IOrganizationService ConnectToCRM()
{
IOrganizationService organizationService = null;
try
{
ClientCredentials clientCredentials = new ClientCredentials();
clientCredentials.UserName.UserName = \"\";
clientCredentials.UserName.Password = \"\";
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
organizationService = new OrganizationServiceProxy(new Uri(\"\"),
null, clientCredentials, null);
return organizationService;
}
catch (Exception ex)
{
Console.WriteLine(\"Exception caught - \" + ex.Message);
return organizationService;
}
}
}
}Output:
It is much helpful article about stop test cases. Your blog is having interesting topic as compared to other article on the web. PHP Services Ecommerce website Development Company Magento Service Providers Data Extraction Services Online Payment Gateway CRM Services Bulk Appointments registers Online Appointment Scheduling Software
LikeLike
Great post.It seems to be interesting and gave me lot of information,Thank for sharing it.I am looking forward for new articles.keep it up.Website Development Company in Bangalore | Website Design Company in Bangalore | Mobile App Development Companies in Bangalore | Game Development Companies in Bangalore
LikeLike
Great post with unique information.This blog will really helpful for me to develop my skills in a right way.Thanks for sharing,keep update with your blogs. Website Design Company in Bangalore | Mobile App Development Companies in Bangalore | Website Development Company in Bangalore
LikeLike
Great Article Cloud Computing Projects Networking Projects Final Year Projects for CSE JavaScript Training in Chennai JavaScript Training in Chennai The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training
LikeLike