Fix Clear-PnPDefaultColumnValues not working with taxonomy fields #576
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Clear-PnPDefaultColumnValues currently throws a NullDereferenceException when invoked on taxonomy fields.
This PR fixes the exception caused by
GetDefaultColumnValueFromField()
returning null when an empty array is passed as argument (meaning "no default taxonomy values"), returning instead aDefaultColumnTermValue
object with no terms in it, and changesSetDefaultColumnValuesImplementation
to clear any default column value if there are none left to be kept.In addition to this I added a null check in ListExtensions.ClearDefaultColumnValues() as it was triggering a null exception when the folder "Forms" was not present (I didn't investigate further if this happens only in special cases, like modern lists just provisioned).
Fixes pnp/powershell#1110 , https://github.com/MicrosoftDocs/OfficeDocs-SharePoint-PowerShell/issues/130 , pnp/PnP-PowerShell#1978
Tests done:
Add a default taxonomy value, then remove it and expect no default values left

Add a default taxonomy value and a default string value, then remove the taxonomy and expect the string value to still be there. Remove the string value too and expect no default values left

Apply a PnP Template with some lists and different column types