pnpcore icon indicating copy to clipboard operation
pnpcore copied to clipboard

TaxonomyFieldValue label property not correctly loaded.

Open gerrylaenen opened this issue 7 months ago • 0 comments

Category

  • [x] Bug

Describe the bug

I am using PnP.Framework 1.13 and PnP.Core 1.10 running on .NET 6 LTS.

When getting a list item that contains a managed metadata field, the value of the label is not correctly retrieved. The Id of is correctly populated.

Instead of a string value that shows the term label, I get a number ("19") for the label property. The term is not translated and has no additional custom properties.

Steps to reproduce

using (var ctx = this.GetPnPClientContextForUrl(siteUrl).Result) {

IList list = null;
try
{
    ctx.Web.EnsureProperties(w => w.ServerRelativeUrl);
    ctx.Execute();
    string listServerRelativeUrl = ctx.Web.ServerRelativeUrl + this._settings.RequestListUrl;
    list = ctx.Web.Lists.GetByServerRelativeUrl(listServerRelativeUrl);
}
catch (Exception ex)
{
    throw new ConfigurationErrorsException("Unable to retrieve request list", ex);
}

try
{
    IListItem listItem = list.Items.GetById(id, p => p.All, p => p.FieldValuesAsText);
    ctx.Execute();

   requestItem.AgreementCategory = listItem[Constants.Fields.fldAgreementCategory] == null ? "" : ((FieldTaxonomyValue)listItem[Constants.Fields.fldAgreementCategory])?.Label.ToString();

  //  requestItem.AgreementCategory == "19" instead of "Standard Training"

    return requestItem;
}
catch (Exception ex)
{
    //_logger.LogError($"Error while updating request item with ID '{requestItem.Id}'. Error: {ex.Message}");
    throw;
}

}

Expected behavior

TaxonomyFieldValue should retrieve the correct Label.

Environment details (development & target environment)

I am using PnP.Framework 1.13 and PnP.Core 1.10 running on .NET 6 LTS.

Additional context

Thanks for your contribution! Sharing is caring.

gerrylaenen avatar Nov 27 '23 16:11 gerrylaenen