Entity name by object type code JavaScript

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)

Entity name by object type code – what is the issue

Recently I found myself in a situation where there was no Xrm.Page.data.entity object so getEnityName() could not be used. Yes, there are form where it’s not available 🙂
I thought, phi, piece of cake. I remembered that there is FormEditorWebService.asmx which has a GetEnityId() so I could use it via RemoteCommand. Unfortunatelly, the service returns entity id from database – not the concrete entity record but entity id itself.
There must be some built-in method, maybe in RetrieveEntityRequest – but again no good because it needs entity logical name to get the metadata. So is there other way go get entity name by object type code only? Especially in Javascript?


After a while I found out the only possible resolution – RetrieveAllEntitiesMetadata request.

	GetCurrentEntityName: function(){
		if(currentEntityName != null){
			return currentEntityName;
		var entitiesMetadata = XrmServiceToolkit.Soap.RetrieveAllEntitiesMetadata(["Entity"], true),
			typeCode = Xrm.Page.context.getQueryStringParameters().objectTypeCode;
		 for(var i = 0; i <= entitiesMetadata.length; i++){
			var entity = entitiesMetadata[i];
			if(entity.ObjectTypeCode == parseInt(typeCode)){
				currentEntityName = entity.LogicalName;

		return currentEntityName;


P.S. If you found this post useful please rate it.

Have an own opinion?