Skip to content

Fix issue #4255 #4262

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions src/Commands/Lists/RestoreListItemVersion.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Linq;
using System;
using System.Linq;
using System.Management.Automation;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.Taxonomy;
using PnP.PowerShell.Commands.Base.PipeBinds;
using PnP.PowerShell.Commands.Extensions;
using Resources = PnP.PowerShell.Commands.Properties.Resources;
Expand Down Expand Up @@ -71,7 +73,29 @@ protected override void ExecuteCmdlet()
var field = fields.FirstOrDefault(f => f.InternalName == fieldValue.Key || f.Title == fieldValue.Key);
if (field is { ReadOnlyField: false, Hidden: false } && !UnsupportedFieldTypes.Contains(field.FieldTypeKind))
{
item[field.InternalName] = fieldValue.Value;
if (field is TaxonomyField)
{
TaxonomyField taxField = ClientContext.CastTo<TaxonomyField>(field);
taxField.EnsureProperty(tf => tf.AllowMultipleValues);
if (taxField.AllowMultipleValues)
{
TaxonomyFieldValueCollection values = (TaxonomyFieldValueCollection)(fieldValue.Value);
var termValuesString = String.Empty;
if (values.Count > 0)
{
foreach (var term in values)
{
termValuesString += "-1;#" + term.Label + "|" + term.TermGuid + ";#";
}
termValuesString = termValuesString.Substring(0, termValuesString.Length - 2);
}

var newTaxFieldValue = new TaxonomyFieldValueCollection(ClientContext, termValuesString, taxField);
taxField.SetFieldValueByValueCollection(item, newTaxFieldValue);
continue;
}
}
item[field.InternalName] = fieldValue.Value;
}
}

Expand Down
Loading