Office 365: Taxonomy fields on newly created site

Site creation

Office 365 provides great and really fast way to create a new modern site collection (do you remember how long it took to provision a classic site?). It helps a lot to boost users experience as they can see almost immediate results.

However, in most organizations there is a requirement to execute provisioning of additional assets based on ‘site designes’ or ‘pnp templates’. Recently, I have faced a situation when wanted to apply PnP provisioning template to a newly created site that contained content types with taxonomy fields.

SP Taxonomy fields

Just as a quick reminder, to use taxonomy fields it is required to add 2 special fields to a list/content type. These are:

  • TaxCatchAll
  • TaxCatchAllLabel

Which are lookup fields and point to the TaxonomyHiddenList. You can find deep explanation of those roles in a fantastic article of Andrew Connel Managed Metadata: In Depth Look into the Taxonomy Parts.

In fact, these fields are not created immediately after the sites creation, but are added later. Most probably by a timer job, as they are available on the site more or less after 5-6 minutes after site creation. But why do we have to wait that time to get what we really need?

Taxonomy hidden fields provisioning

After trying few other times to force O365 to provision those fields for me, I have decided – OK, they are not there, so let’s create them. However, to execute provisioning of those fields – we need one prerequisite. As we have already said, these are lookup columns and point to taxonomy hidden list, so we have to be sure that it exists before the provisioning.

We can easily ensure it by activating the taxonomy site scope feature:

Enable-PnPFeature -Identity 73ef14b1-13a9-416b-a9b5-ececa2b0604c -Scope Site

After that, we need to get it’s Id and pass it as a parameter to our provisioning template as a parameter. After we can execute the provisioning of required fields:

$list = Get-PnPList -Identity "TaxonomyHiddenList";
$web = Get-PnPWeb;
$params = @{ "TaxonomyHiddenListId" = $list.Id; "WebId" = $web.Id }
Apply-PnPProvisioningTemplate -Path $templatePath -Parameters $params

Here is the content of the provisioning template:

<?xml version="1.0"?>
<pnp:Preferences Generator="OfficeDevPnP.Core, Version=2.20.1711.0, Culture=neutral, PublicKeyToken=3751622786b357c2" />
<pnp:Templates ID="TaxonomyPrerequisite-TEMPLATES">
<pnp:ProvisioningTemplate ID="ValoPrerequisite-v-1.0" Version="1" Scope="RootSite">
<Field Type="LookupMulti" DisplayName="Taxonomy Catch All Column" StaticName="TaxCatchAll" Name="TaxCatchAll" ID="{f3b0adf9-c1a2-4b02-920d-943fba4b3611}" ShowInViewForms="FALSE" List="{parameter:TaxonomyHiddenListId}" WebId="{parameter:WebId}" Required="FALSE" CanToggleHidden="TRUE" ShowField="CatchAllData" SourceID="{484c8c59-755d-4516-b8d2-1621b38262b4}" Mult="TRUE" Sortable="FALSE" AllowDeletion="TRUE" Sealed="TRUE" Hidden="TRUE" />
<Field Type="LookupMulti" DisplayName="Taxonomy Catch All Column1" StaticName="TaxCatchAllLabel" Name="TaxCatchAllLabel" ID="{8f6b6dd8-9357-4019-8172-966fcd502ed2}" ShowInViewForms="FALSE" List="{parameter:TaxonomyHiddenListId}" WebId="{parameter:WebId}" Required="FALSE" Hidden="TRUE" CanToggleHidden="TRUE" ShowField="CatchAllDataLabel" FieldRef="{F3B0ADF9-C1A2-4b02-920D-943FBA4B3611}" SourceID="{484c8c59-755d-4516-b8d2-1621b38262b4}" ReadOnly="TRUE" Mult="TRUE" Sortable="FALSE" AllowDeletion="TRUE" Sealed="TRUE" />

Thanks to this approach, you won’t need to wait till O365 will provision required fields to deploy your stuff. Enjoy!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s