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

Merged
merged 1 commit into from
Nov 7, 2019
Merged

Allow -1 to be used for taxonomy fields in pnp:FieldDefault #2329

merged 1 commit into from
Nov 7, 2019

Conversation

KoenZomers
Copy link
Contributor

Q A
Bug fix? no
New feature? no
New sample? no
Related issues? N/A

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).

…eld 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
@PaoloPia PaoloPia changed the base branch from master to dev November 7, 2019 17:37
PaoloPia added a commit to PaoloPia/PnP-Sites-Core that referenced this pull request Nov 7, 2019
PaoloPia added a commit that referenced this pull request Nov 7, 2019
@PaoloPia PaoloPia merged commit 03589de into pnp:dev Nov 7, 2019
@PaoloPia
Copy link
Contributor

PaoloPia commented Nov 7, 2019

Hi @KoenZomers,
Thanks for your contribution. This PR has been merged.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants