Skip to content
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

Fix Clear-PnPDefaultColumnValues not working with taxonomy fields #576

Merged
merged 2 commits into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -859,13 +859,15 @@ public static IDefaultColumnValue GetDefaultColumnValueFromField(this Field fiel
terms.Add(term);
}
}

defaultColumnValue = new DefaultColumnTermValue()
{
FieldInternalName = field.InternalName,
FolderRelativePath = folderRelativePath,
};

if (terms.Any())
{
defaultColumnValue = new DefaultColumnTermValue()
{
FieldInternalName = field.InternalName,
FolderRelativePath = folderRelativePath,
};
terms.ForEach(t => ((DefaultColumnTermValue)defaultColumnValue).Terms.Add(t));
}
}
Expand Down
37 changes: 21 additions & 16 deletions src/lib/PnP.Framework/Extensions/ListExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1656,7 +1656,9 @@ public static View GetViewByName(this List list, string name, params Expression<

private static void SetDefaultColumnValuesImplementation(this List list, IEnumerable<IDefaultColumnValue> columnValues)
{
if (columnValues == null || !columnValues.Any()) return;
if (columnValues == null || !columnValues.Any())
list.ClearDefaultColumnValues();

using (var clientContext = list.Context as ClientContext)
{
try
Expand Down Expand Up @@ -1991,23 +1993,26 @@ public static void ClearDefaultColumnValues(this List list)

// Check if default values file is present
var formsFolder = list.RootFolder.Folders.FirstOrDefault(x => x.Name == "Forms");
var configFile = formsFolder.Files.GetByUrl(defaultValuesFileName);
clientContext.Load(configFile, c => c.Exists);
bool fileExists = false;
try
{
clientContext.ExecuteQueryRetry();
fileExists = true;
}
catch
if (formsFolder != null)
{
// Do nothing here
}
var configFile = formsFolder.Files.GetByUrl(defaultValuesFileName);
clientContext.Load(configFile, c => c.Exists);
bool fileExists = false;
try
{
clientContext.ExecuteQueryRetry();
fileExists = true;
}
catch
{
// Do nothing here
}

if (fileExists)
{
configFile.DeleteObject();
clientContext.ExecuteQueryRetry();
if (fileExists)
{
configFile.DeleteObject();
clientContext.ExecuteQueryRetry();
}
}
}
}
Expand Down