microsoft / PowerPlatform-DataverseServiceClient

Code Replica for Microsoft.PowerPlatform.Dataverse.Client and supporting nuget packages.
MIT License
283 stars 52 forks source link

Metadata DisplayName LocalizedLabels sometimes null #433

Closed BernhardWeidingerACE closed 7 months ago

BernhardWeidingerACE commented 9 months ago

Hi, we are trying to get attribute display names of certain entities via metadata requests. Sometimes (but not always) the requests doesn't return the LocalizedLabels. We tried multiple ways to get the metadata, for example with the RetrieveMetadataChangesRequest, but the behaviour stays the same. An example request looks like this:

ServiceClient client = new ServiceClient("AuthType=ClientSecret;Url=ZZZ;ClientId=XXX;ClientSecret=YYY");
if (client.IsReady)
{
    client.ResetLocalMetadataCache("contact");
    var attr = client.GetEntityAttributeMetadataForAttribute("contact", "address2_line1");

    RetrieveMetadataChangesRequest retrieveMetadataChangesRequest = new RetrieveMetadataChangesRequest();

    var attrCriteria = new MetadataFilterExpression();
    attrCriteria.Filters.Add(new MetadataFilterExpression()
    {
        Conditions =
        {
            new MetadataConditionExpression("LogicalName", MetadataConditionOperator.Equals, "address2_line1")
        }
    });

    attrCriteria.Filters.Add(new MetadataFilterExpression()
    {
        Conditions =
        {
            new MetadataConditionExpression("IsRetrievable", MetadataConditionOperator.Equals, false)
        }
    });

    retrieveMetadataChangesRequest.Query = new EntityQueryExpression()
    {
        Criteria = new MetadataFilterExpression()
        {
            Conditions =
            {
                new MetadataConditionExpression("LogicalName", MetadataConditionOperator.Equals, "contact")
            }
        },
        AttributeQuery = new AttributeQueryExpression()
        {
            Criteria = attrCriteria,
            Properties = new MetadataPropertiesExpression()
            {
                AllProperties = true
            }
        },
        Properties = new MetadataPropertiesExpression()
        {
            AllProperties = false,
            PropertyNames = { "Attributes" }
        }
    };

    RetrieveMetadataChangesResponse response = client.Execute(retrieveMetadataChangesRequest) as RetrieveMetadataChangesResponse;

    var result = response.EntityMetadata[0];
    var labels = result.Attributes[0].DisplayName.LocalizedLabels; //labels.Count sometimes 0

    //same behaviour as before:
    //RetrieveEntityRequest req = new RetrieveEntityRequest();
    //req.LogicalName = "contact";
    //req.RetrieveAsIfPublished = false;
    //req.EntityFilters = EntityFilters.Attributes;

    //RetrieveEntityResponse response = client.Execute(req) as RetrieveEntityResponse;

    //var attr = response.EntityMetadata.Attributes.Where(a => a.LogicalName=="address2_line1").First();

    //while (attr.DisplayName.LocalizedLabels.Count <= 0)
    //{
    //    RetrieveAttributeRequest request = new() 
    //    { 
    //        EntityLogicalName = "contact", 
    //        LogicalName = "address2_line1"
    //    };         
    //    var response2 = (RetrieveAttributeResponse)client.Execute(request);
    //    attr = response2.AttributeMetadata;
    //}
}
MattB-msft commented 8 months ago

Are you seeing this inconsistently for the same entity/attribute in the same environment? if so, that would be something we would want to have a support ticket opened with a request ID so that the environment itself can be investigated.

MattB-msft commented 7 months ago

Going to close this at this time.
This would need to be taken up with support.