Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 79901

Restricting languages returned in Optionset metadata query

$
0
0

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?


Viewing all articles
Browse latest Browse all 79901

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>