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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Restricting languages returned in Optionset metadata query

(0) ShareShare
ReportReport
Posted on by 25

I might have found a bug with the Metadata query to do with the optionset labels returned from Metadata queries.

If you query with a LabelQueryExpression and specify just a single language LCID, the display names for the attributes and entities only return the correct language, but optionset value labels seem to always return all languages? Is this something anyone else has seen?

Below is my unit test that gets the statuscode attribute for account and then checks there is only a single label returned (1033) for the status code attribute on the account.

For an org with more than 1 language – it passes on the first test for DisplayName, but fails for the optionset check.

[TestMethod]

public void GetSingleLanguageForOptionsetLabels()

{

   EntityQueryExpression query = new EntityQueryExpression

   {

       Properties = new MetadataPropertiesExpression("DisplayName", "Attributes"),

       LabelQuery = new LabelQueryExpression(),

       Criteria = new MetadataFilterExpression(LogicalOperator.And),

       AttributeQuery = new AttributeQueryExpression

       {

           Criteria = new MetadataFilterExpression(LogicalOperator.And),

           Properties = new MetadataPropertiesExpression("OptionSet")

       }

   };

   query.LabelQuery.FilterLanguages.Add(1033);

   query.Criteria.Conditions.Add(

               new MetadataConditionExpression(

               "LogicalName", MetadataConditionOperator.Equals, Account.EntityLogicalName));

               query.AttributeQuery.Criteria.Conditions.Add(

           new MetadataConditionExpression(

               "LogicalName", MetadataConditionOperator.Equals, "statuscode"));

   RetrieveMetadataChangesRequest request = new RetrieveMetadataChangesRequest

   {

       ClientVersionStamp = null,

       Query = query

   };

   RetrieveMetadataChangesResponse response = (RetrieveMetadataChangesResponse)_service.Execute(request);

   DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(RetrieveMetadataChangesResponse));

   // Check we only have a single language for the display name

   var accountDisplayNameLabels = from e in response.EntityMetadata

                                 where e.LogicalName == Account.EntityLogicalName

                                 from l in e.DisplayName.LocalizedLabels

                                 select l;

   Assert.AreEqual(accountDisplayNameLabels.Count(), 1, "Should be only 1033 returned in Entity Display Name labels");

   // Check we only have a single language for the first optionset display name

   var accountStatusCodeLabels = from e in response.EntityMetadata

                                 where e.LogicalName == Account.EntityLogicalName

                                 from a in e.Attributes

                                 where a.LogicalName == "statuscode"

                                 from o in ((EnumAttributeMetadata)a).OptionSet.Options.Take(1)

                                 from l in o.Label.LocalizedLabels

                                 select l;

   Assert.AreEqual(accountStatusCodeLabels.Count(), 1,"Should be only 1033 returned in Optionset labels");

}

Can anyone spot anything wrong here?

*This post is locked for comments

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans