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?
Solution
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; break; } } return currentEntityName; },
P.S. If you found this post useful please rate it.