PowerPlatform-DataverseServiceClient icon indicating copy to clipboard operation
PowerPlatform-DataverseServiceClient copied to clipboard

Metadata DisplayName LocalizedLabels sometimes null

Open BernhardWeidingerACE opened this issue 1 year ago • 1 comments

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;
    //}
}

BernhardWeidingerACE avatar Feb 22 '24 15:02 BernhardWeidingerACE

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 avatar Feb 27 '24 04:02 MattB-msft

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

MattB-msft avatar Apr 01 '24 17:04 MattB-msft