Pulling the Display name of an attribute from entity Metadata

1.5k views Asked by At

I am fairly new at trying to get data from CRM using C#, I am trying to get the display names of all of my attribute on CRM, When I try, I am getting a result of Microsoft.Xrm.Sdk.Label and it doesn't seem to straight forward to get the value of that label, could someone point me in the right direction?

using System;    
using Microsoft.Xrm.Tooling.Connector;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Metadata;


namespace CRM_MetaData_Download
{
    class Program
    {
        static void Main(string[] args)
        {
            try {
                var connectionString = @"AuthType = Office365; Url = https://CRMINFORMATION";
                CrmServiceClient conn = new CrmServiceClient(connectionString);

                IOrganizationService service;
                service = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;
                RetrieveEntityRequest retrieveEntityRequest = new RetrieveEntityRequest
                {
                    EntityFilters = EntityFilters.All,
                    LogicalName = "account"
                };
                RetrieveEntityResponse retrieveAccountEntityResponse = (RetrieveEntityResponse)service.Execute(retrieveEntityRequest);
                EntityMetadata AccountEntity = retrieveAccountEntityResponse.EntityMetadata;

                Console.WriteLine("Account entity attributes:");
                foreach (object attribute in AccountEntity.Attributes)
                {
                    AttributeMetadata a = (AttributeMetadata)attribute;
                    Console.WriteLine(a.LogicalName + "    " +
                        a.Description + "    " +
                        a.DisplayName + "    " +
                        a.EntityLogicalName + "    " +
                        a.SchemaName + "    " +
                        a.AttributeType + "    "
                        );
                }
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }

    }
}
1

There are 1 answers

5
Arun Vinoth-Precog Tech - MVP On BEST ANSWER

Since Dynamics CRM supports multi-lingual capabilities, the display name label will be stored for each language. You can get it like below:

a.DisplayName.UserLocalizedLabel.Label