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 Clear-PnPDefaultColumnValues not working with taxonomy fields #576

Merged
merged 2 commits into from
Feb 7, 2022

Conversation

jackpoz
Copy link
Contributor

@jackpoz jackpoz commented Jan 14, 2022

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 a DefaultColumnTermValue object with no terms in it, and changes SetDefaultColumnValuesImplementation 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:

  1. Add a default taxonomy value, then remove it and expect no default values left
    image

  2. 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
    image

  3. Apply a PnP Template with some lists and different column types

@jansenbe jansenbe self-assigned this Feb 7, 2022
jansenbe added a commit that referenced this pull request Feb 7, 2022
@jansenbe jansenbe merged commit dc18318 into pnp:dev Feb 7, 2022
@jackpoz jackpoz deleted the fixes/cleardefaultcolumnvalues-taxonomy branch December 4, 2022 15:37
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] Clear-PnPDefaultColumnValues does not work for Managed Metadata/Taxonomy fields
2 participants