web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

C# Retrieve Attributes Metadata with DisplayLabel

(0) ShareShare
ReportReport
Posted on by 365

Hi experts,

I'ma facing some issue while trying to retrieve all attributes metadata. I would like to get all the attributes and their metadata for a specific entity (account for example). The first thing to do is a RetrieveEntityRequest like this:

var eMetadataRequest = new RetrieveEntityRequest { EntityFilters = EntityFilters.Attributes, LogicalName = "account" };
var eMetadataResponse = (RetrieveEntityResponse)crmService.Execute(eMetadataRequest);
var accountMetadata = eMetadataResponse.EntityMetadata;

But, the display name for many attributes are null on the result (while they're not in CRM)

accountMetadata.Attributes[0].DisplayName.UserLocalizedLabel


I know that there is a request of type RetrieveAttributeMetadata (that returns display name also)

var attReq = new RetrieveAttributeRequest { EntityLogicalName = "account", LogicalName = "preferredcontactmethodcode"  };
var attRes = (RetrieveAttributeResponse)Service.Execute(attReq);


But I would not write a loop for all attributes retrieved on the first request to get displayName...

There is a parameter I missing on the first request? Or any other solution?

I would just like to point out that I have only one language installed on CRM

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    Try this:

    accountMetadata.Attributes[0].DisplayName.UserLocalizedLabel.Label

    or

    accountMetadata.Attributes[0].DisplayName.LocalizedLabels[0].Label

    Refer:

    dynamics365blocks.wordpress.com/.../how-to-retrieve-display-name-of-an-attribute-in-dynamics-crm-using-c

  • Moshe Hayun Profile Picture
    365 on at

    Hi

    Thank you for the answer. But, accountMetadata.Attributes[0].DisplayName.UserLocalizedLabel is NULL, so it's not possible to use its Label property.

  • Community Member Profile Picture
    on at

    Are you getting value in accountMetadata.Attributes[0] or is it null.

    Your First request is for EntityMetadata which returns account entity metadata. You won't be able to get Attributes in your first request.

    msdn.microsoft.com/.../microsoft.xrm.sdk.metadata.entitymetadata.aspx

    You have to loop through all the attributes in your second request in order to get displayname of Attributes.

    msdn.microsoft.com/.../microsoft.xrm.sdk.metadata.attributemetadata.aspx

  • Verified answer
    Moshe Hayun Profile Picture
    365 on at

    Yes, I get a value on accountMetadata.Attributes[0]

    Finally, I just found my answer: RetrieveEntityRequest returns attribute metadata including displayName only for real attributes, like primarycontactid, preferredcontactmethodcode and so on... But not for "calculated" attribute, like primarycontactidNAME, or preferredcontactmethodcodeNAME... there is an property called "AttributeOf", if this property is not null, it means that current attribute is "calculcated".

    Thank you for the help. It is when I debogged to make screenshots of the watches in order to show them to you, that I discovered this nuance.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans