Skip to content

Commit

Permalink
Fix Set-PnPListItem not saving taxonomy values when using -Batch para…
Browse files Browse the repository at this point in the history
…meter
  • Loading branch information
jackpoz committed Nov 30, 2024
1 parent 3e9dc7d commit 680b8bb
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/Commands/Utilities/ListItemHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -423,21 +423,22 @@ public static Dictionary<string, object> GetFieldValues(PnP.Core.Model.SharePoin
var label = string.Empty;
var itemId = Guid.Empty;

if (!Guid.TryParse(arrayItem as string, out termGuid))
if (!Guid.TryParse(arrayItem?.ToString(), out termGuid))
{
var batchedTerm = batch.GetCachedTerm(termGuid.ToString());
var batchedTerm = batch.GetCachedTerm(arrayItem?.ToString());
if (batchedTerm.key == null)
{
taxonomyItem = clientContext.Site.GetTaxonomyItemByPath(arrayItem as string) as Term;
taxonomyItem = clientContext.Site.GetTaxonomyItemByPath(arrayItem?.ToString()) as Term;
if (taxonomyItem == null)
{
throw new PSInvalidOperationException($"Cannot find term {arrayItem}");
throw new PSInvalidOperationException($"Cannot find term '{arrayItem}'");
}
var labelResult = taxonomyItem.GetDefaultLabel(defaultLanguage);
clientContext.ExecuteQueryRetry();
label = labelResult.Value;
itemId = taxonomyItem.Id;
batch.CacheTerm(termGuid.ToString(), termGuid, label);
batch.CacheTerm(arrayItem?.ToString(), itemId, label);
batch.CacheTerm(itemId.ToString(), itemId, label);
}
else
{
Expand Down Expand Up @@ -467,10 +468,12 @@ public static Dictionary<string, object> GetFieldValues(PnP.Core.Model.SharePoin
itemId = batchedTerm.id;
label = batchedTerm.label;
}
fieldValueCollection.Values.Add(field.NewFieldTaxonomyValue(itemId, label));
}
item[key as string] = fieldValueCollection;

fieldValueCollection.Values.Add(field.NewFieldTaxonomyValue(itemId, label));
}

item[key as string] = fieldValueCollection;
}
else
{
Expand Down

0 comments on commit 680b8bb

Please sign in to comment.