Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix Copy-PnPList handling of lookup columns #3870

Merged
merged 2 commits into from
Apr 8, 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
12 changes: 9 additions & 3 deletions src/Commands/Lists/CopyList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
using Microsoft.SharePoint.Client;
using PnP.PowerShell.Commands.Base.PipeBinds;
using System;
using System.Text.RegularExpressions;
using System.Linq;
using PnP.PowerShell.Commands.Utilities.REST;
using PnP.PowerShell.Commands.Model.SharePoint;
using System.Text.Json.Nodes;

namespace PnP.PowerShell.Commands.Lists
{
Expand Down Expand Up @@ -69,9 +69,15 @@ protected override void ExecuteCmdlet()

if (ParameterSpecified(nameof(Title)) && !string.IsNullOrWhiteSpace(Title))
{
// Update the list name in the site script using a regular expression
// Update the list name in the site script in the first *_listName binding parameter
WriteVerbose($"Setting list title to '{Title}'");
script = Regex.Replace(script, "(?<=\"listName\":\\s?\")(.*?)(?=\")", Title);

JsonNode scriptAsJson = JsonNode.Parse(script);

var listNameElement = scriptAsJson["bindings"].AsObject().Where(b => b.Key.EndsWith("_listName")).First();
listNameElement.Value["defaultValue"] = Title;

script = scriptAsJson.ToJsonString();
}

// Check if we need to set the destination to the current site
Expand Down
Loading