locked
Get entity display name in JavaScript using SDK.Metadata.js in Microsoft Dynamics CRM 2013 RRS feed

  • Question

  • Hi,

    I have created a custom entity in my Microsoft Dynamics CRM 2013 environment. I have added "SDK.Metada.js" and "Json2.js" on entity form. I have written following JavaScript code to retrieve entity logical name-

    retrievedEntityMetadataCollection[i].LogicalName.toString()

    I want entity display name instead of entity logical name. 

    Is there any way to get this?

    Wednesday, January 28, 2015 1:40 PM

Answers

  • Try entityMetaDataCollection[0].DisplayName.UserLocalizedLabel.Label:

     SDK.Metadata.RetrieveAllEntities(SDK.Metadata.EntityFilters.Entity,
                false,
                function (entityMetaDataCollection) {
                    if (entityMetaDataCollection != null) {
                        alert(entityMetaDataCollection[0].DisplayName.UserLocalizedLabel.Label);
                    }
                },
                function (error) {
                },
                null
                );
    Kind Regards
    • Marked as answer by P H S Friday, January 30, 2015 11:49 AM
    Thursday, January 29, 2015 7:50 AM

All replies

  • Hello,

    Could you please provide code you use? Not just small part of it?


    Dynamics CRM MVP/ Technical Evangelist at SlickData LLC
    My blog

    Wednesday, January 28, 2015 2:05 PM
    Moderator
  • try

    retrievedEntityMetadataCollection.LogicalName


    Regards Faisal

    Wednesday, January 28, 2015 3:12 PM
  • Hello

    Use this sample: https://msdn.microsoft.com/en-us/library/gg594428.aspx

    The SDK.MetaData.RetrieveEntity function does the same as the RetrieveEntityRequest (Microsoft.Xrm.Sdk.Messages) in C#/VB. (Code below is JS :p) :

    SDK.Metadata.RetrieveEntity(SDK.Metadata.EntityFilters.Attributes,
        id,
        null,
        false,
        function (entityMetadata) { successRetrieveEntity(entityLogicalName, entityMetadata); },
        errorRetrieveEntity);
     

    As the RetrieveEntityRequest in C#/VB returns a RetrieveEntityResponse with a Property of type 'EntityMetadata' wich contains a property DisplayName,
    I think the object entityMetadata passed in the succesRetrieveEntity() function has an attribute with the display name. (didn't try it).

    The XrmServiceToolkit (http://xrmservicetoolkit.codeplex.com/) has a similar function that doesn't expect an id of an entity as a parameter (RetrieveEntityMetadata).There is a lot more information in the XrmServiceToolkit.js file (variables to pass etc etc,...)

    var retrieveEntityMetadata = function (entityFilters, logicalName, retrieveIfPublished, callback)

    • Edited by Jochen- Wednesday, January 28, 2015 4:10 PM
    Wednesday, January 28, 2015 4:09 PM
  • Thanks Andrii.

    I have written following JavaScript code on form load event-

    function retrieveAllEntitiesForCreate() {

    // EntityFilters, RetrieveAsIfPublished, successCallBack, errorCallBack, passThroughObject

      SDK.Metadata.RetrieveAllEntities(SDK.Metadata.EntityFilters.Entity,

       false,

       successRetrieveAllEntitiesForCreate,

       errorRetrieveAllEntitiesForCreate,

      null);

     }

    function successRetrieveAllEntitiesForCreate(entityMetadataCollection) {

     if (entityMetadataCollection != null) {

      var entityDataArray = [];

      for (var entityNumber = 0; entityNumber < entityMetadataCollection.length; entityNumber++) {

       var entityLogicalName = entityMetadataCollection[entityNumber].LogicalName.toString();

       entityDataArray.push([entityLogicalName, entityNumber]);

       }

     }

    }

    Here, when I use "entityMetadataCollection[entityNumber].DisplayName.toString();" instead of "entityMetadataCollection[entityNumber].LogicalName.toString();" then I get "[object][object]".

    Any work around for this?

    Thursday, January 29, 2015 6:35 AM
  • Thank you. I have posted my JavaScript code above. 
    Thursday, January 29, 2015 6:39 AM
  • Thanks Faisal. I am using the same thing currently. But, to enhance the functionality, want to have entity display name instead of entity logical name. I have posted my JavaScript code above.

    Any idea if is it possible or not?

    • Edited by P H S Thursday, January 29, 2015 6:42 AM
    Thursday, January 29, 2015 6:41 AM
  • Try entityMetaDataCollection[0].DisplayName.UserLocalizedLabel.Label:

     SDK.Metadata.RetrieveAllEntities(SDK.Metadata.EntityFilters.Entity,
                false,
                function (entityMetaDataCollection) {
                    if (entityMetaDataCollection != null) {
                        alert(entityMetaDataCollection[0].DisplayName.UserLocalizedLabel.Label);
                    }
                },
                function (error) {
                },
                null
                );
    Kind Regards
    • Marked as answer by P H S Friday, January 30, 2015 11:49 AM
    Thursday, January 29, 2015 7:50 AM
  • Thanks you. That really works.
    • Marked as answer by P H S Friday, January 30, 2015 11:49 AM
    • Unmarked as answer by P H S Friday, January 30, 2015 11:49 AM
    Friday, January 30, 2015 11:48 AM