Recently, i got a requirement to get the display name of attributed of an entity in C# code. This was basically a part of building an application to retrieve the Name and option set values of all option sets of any selected entity.
Anyway, i’ll update about that later when the application is finished but for now i feel sharing the code to retrieve the Label name of attributes which can give you the label of attribute if you pass it the schema name of entity, schema name of attribute and Iorganisation service object.
Class to include:
Write “using Microsoft.Xrm.Sdk.Messages;” to include the same.
Code Snippet:
///////////////////////////////////////////////////////////////////////////
public static string RetrieveAttributeDisplayName( string EntitySchemaName, string AttributeSchemaName, IOrganizationService service) { RetrieveAttributeRequest retrieveAttributeRequest = new RetrieveAttributeRequest { EntityLogicalName = EntitySchemaName, LogicalName = AttributeSchemaName, RetrieveAsIfPublished = true }; RetrieveAttributeResponse retrieveAttributeResponse = (RetrieveAttributeResponse)service.Execute(retrieveAttributeRequest); AttributeMetadata retrievedAttributeMetadata = (AttributeMetadata)retrieveAttributeResponse.AttributeMetadata; //Get Length // Int32 length = (Int32)((Microsoft.Xrm.Sdk.Metadata.StringAttributeMetadata)retrievedAttributeMetadata).MaxLength; return retrievedAttributeMetadata.DisplayName.UserLocalizedLabel.Label; }
///////////////////////////////////////////////////////////////////////////
Hope the post will be helpful.
Thanks
HI,
I have a requirement to know the Entity Schema Name based on the Attribute Schema Name.
Is this even possible to get this value using sdk code in C#?
Thanks,
Bipin
LikeLike