Skip to content

Conversation

@jackpoz
Copy link
Contributor

@jackpoz jackpoz commented Nov 30, 2024

Type

  • Bug Fix
  • New Feature
  • Sample

Related Issues?

Fixes #4475

What is in this Pull Request ?

Fix Set-PnPListItem not saving taxonomy values when using -Batch parameter. The -Batch parameter has a different code path when using -Batch and when passing terms in format TermGroup|TermSet|Term1 instead of a guid.

The issues fixed related to -Batch and taxonomy terms passed with the format TermGroup|TermSet|Term1 are:

  • fieldValueCollection.Values.Add(field.NewFieldTaxonomyValue(itemId, label)); was never called, so the term was never included in the updates
  • batch.CacheTerm(termGuid.ToString(), termGuid, label); used termGuid after Guid.TryParse(arrayItem as string, out termGuid) failed, meaning it was always an empty guid 00000000-0000-0000-0000-000000000000, causing any later iteration to return an empty cached term
  • batch.CacheTerm() now uses as key the format TermGroup|TermSet|Term1 in addition to term id, making the cache useful when all terms are in that format. Before the cache worked only with guid format.

Example of running the script:
image

Script sample similar to the one from #4475

$list = 'List with taxonomy'
$ID = 1
# Store the terms in an array
$terms = @()
$terms += 'This is a test|Column with taxonomy|Test 1'
$terms += 'This is a test|Column with taxonomy|Test 1'
$terms += 'This is a test|Column with taxonomy|Test 2'
$terms += "271a4dae-c22f-4ba4-b79c-50dad60bd8c3"

$batch = New-PnPBatch

Set-PnPListItem -List $list -Identity $ID -UpdateType "UpdateOverwriteVersion" -Values @{"Column_x0020_with_x0020_taxonomy" = $terms; "Title" = (Get-Date).ToLongTimeString()} -Batch $batch

Invoke-PnPBatch -Batch $batch

@gautamdsheth gautamdsheth merged commit 472a561 into pnp:dev Dec 15, 2024
2 checks passed
@gautamdsheth
Copy link
Collaborator

Thanks @jackpoz , good catch, merged the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] When using Set-PnPListItem in batch mode managed metadata column values are not being set when multiple terms are provided

2 participants