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)

Restricting languages returned in Optionset metadata query

(0) ShareShare
ReportReport
Posted on by 21

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

I have the same question (0)

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