This repository has been archived by the owner on Jan 19, 2021. It is now read-only.
Allow -1 to be used for taxonomy fields in pnp:FieldDefault #2329
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.
What's in this Pull Request?
When providing a FieldDefaults under a ListInstance for a taxonomy field and setting the ID to -1, this code change will make sure to update the -1 to the actual ID as it exists in the hidden TaxonomyHiddenList list or if it doesn't exist in there yet, create a new entry for it and update the -1 to the ID of this new entry.
To test this, create a PnP Provisioning Template by i.e. exporting an existing site. Inside a
<pnp:ListInstance> ... </pnp:ListInstance>
element, add:<pnp:FieldDefaults> <pnp:FieldDefault FieldName="TaxSiteField">-1;#Value 3|3d30ef63-d5a4-42fa-909c-5cd578223132</pnp:FieldDefault> </pnp:FieldDefaults>
Update TaxSiteField with the internal name of an actual taxonomy field in your list and replace the Value 3 and GUID behind the pipe symbol with an actual value in the taxonomy term you have the taxonomy field linked to. Now Apply-PnPProvisiningTemplate the template. Once done, request the field default value using i.e.
get-pnplist -Identity ListName | get-pnpfield | select title,defaultvalue
Replace ListName with the list you referred to with your ListInstance in the PnP Provisioning Template above. Instead of showing "-1;#Value 3|3d30ef63-d5a4-42fa-909c-5cd578223132" as the defaultvalue it should now show the actual ID of the taxonomy item in the TaxonomyHiddenList, i.e. 2;#Value 3|3d30ef63-d5a4-42fa-909c-5cd578223132. Before this PR, it would not take the -1 as a special case and just leave it as a -1. Inside a SiteField the Field Default node would already have the -1 treated as a special case, i.e.:
<Default>-1;#Value 2|7aa6591c-8530-4f13-9552-6013bf0eeff2</Default>
Would work, but again the pnp:FieldDefault didn't work this way. With this PR they now both work and can handle -1 just as well as absolute values (1, 2, 3, etc).