Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

C# Retrieve Attributes Metadata with DisplayLabel

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

  • Verified answer
    Moshe Hayun Profile Picture
    Moshe Hayun 365 on at
    RE: C# Retrieve Attributes Metadata with DisplayLabel

    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.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: C# Retrieve Attributes Metadata with DisplayLabel

    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

  • Moshe Hayun Profile Picture
    Moshe Hayun 365 on at
    RE: C# Retrieve Attributes Metadata with DisplayLabel

    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
    Community Member Microsoft Employee on at
    RE: C# Retrieve Attributes Metadata with DisplayLabel

    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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans