German
German

Reputation: 740

How to retrieve entity name by object type code using JavaScript in CRM?

Is there anyway on client side in Dynamics CRM 2011 from JavaScript to retrieve Entity Logical Name by Object Type Code?

Example: Object Type Code = 1, Logical Name is Account

Upvotes: 2

Views: 1759

Answers (3)

Hsu-Cheng Huang
Hsu-Cheng Huang

Reputation: 1

There's a super easy way.

Using Chrome, and in your CRM site( basically anywhere,) hit F12 go to console, and type:

Mscrm.EntityPropUtil.EntityTypeName2CodeMap

You will see the full list(as picture below) of the EntityTypeName and their Type Code(including your customized entities!)

The sameple list

Upvotes: 0

James Wood
James Wood

Reputation: 17562

Alternatively don't use the object type code at all. Sort of depends on what your exact usage is, but usually you can get straight to the entity name.

For example, Xrm.Page.data.entity.getEntityName() returns the name of the current entity.

Xrm.Page.data.entity

Upvotes: 1

Polshgiant
Polshgiant

Reputation: 3664

This is unsupported, but it does what you want:

function getLogicalNameFromTypeCode(typeCode) {
    return Object.keys(Mscrm.EntityPropUtil.EntityTypeName2CodeMap).filter(function(key) { 
      return Mscrm.EntityPropUtil.EntityTypeName2CodeMap[key] === typeCode;
    })[0];
}

Usage:

getLogicalNameFromTypeCode(1); // 'account'

Source

Upvotes: 3

Related Questions