PnP templates and Termset ID's

PnP templates and Termset ID's header image

Using the [PnP Partner Pack][1] for provisioning in Office 365 is usually pretty awesome! They provide a whole lot of updates and most common scenario’s can be fit into a template and deployed using Remote Provisioning. Yet once every now and then you encounter some weird issues that seems to be unexplainable, and as with all good things in the cloud debugging it is a crime.

Deployment scenario

What we where trying to achieve was to create a template for a specific site that would be deployed multiple times. This site template could be used to create a ‘n’ amount of sites based of that template, and it did contain a wiki page library for the homepage of the site. One of the parts of the template was a adding some info to the termset so users could easily tag their content with corrected terms.

Using the official [Provisioning Schema][2] we came up with the following snippet:

<pnp:TermGroups>
 <pnp:TermGroup Name="{sitecollectiontermgroupname}">
   <pnp:TermSets>
     <pnp:TermSet Name="Wiki categories" ID="3732f6b7-a334-42eb-b9b7-a6fa1fa50fca" Language="1033">
      <pnp:Terms>
        <pnp:Term Name="Prince 2" ID="e26c880b-2ae7-4643-8680-b2aeedc9d632" IsAvailableForTagging="true">
          <pnp:Terms>
            <pnp:Term Name="Closure" ID="3e164b59-570c-6c11-a3fb-e016a4c84d26" IsAvailableForTagging="true" />
            <pnp:Term Name="Discovery" ID="ce9ccbaa-cfe3-6e71-9f37-9556738c70a8" IsAvailableForTagging="true" />
            <pnp:Term Name="Execution" ID="8424aff1-645e-6fb9-816f-e30c2351d413" IsAvailableForTagging="true" />
            <pnp:Term Name="Initiation" ID="31c24d63-1aa6-44e1-8899-205ceeba6b50" IsAvailableForTagging="true" />
          </pnp:Terms>
        </pnp:Term>
      </pnp:Terms>
     </pnp:TermSet>
   </pnp:TermSets>
 </pnp:TermGroup>
</pnp:TermGroups>

Errors

Applying this template the first time went smooth as usual and no problems arose. A few weeks later another request came for the same site and we added a new item with the same template to the queue.. That’s when it went side ways; all of a sudden the template would no longer deploy and started to throw errors. The errors we got where  as follows:

Failed to read from or write to database. Refresh and try again. If the problem persists, please contact the administrator.

The first thing we did was to delete a set of terms that did contain special characters, only to find the error remain. After some debugging we decided to recreate everything and added new Term ID’s and the template started to work again, only to fail the second time again. That resulting in some more googling only to find a blogpost on [Problem with creation of managed metadata term with predefined term id in SharePoint][3]. As it turns out that actually did explain our error, as it states:

As it shows the exact error is that there already was term with the same id in the managed metadata table (Cannot insert duplicate key row in object ‘dbo.ECMTerm’ with unique index ‘IX_ECMTerm_TermGUID’).

Having that post the only explanation would be to never create terms with a predefined ID in the site collection termgroup. Creating terms with a predefined id in a global group would not be a problem as they will only be created once. But as every site has its own site collection term group those terms end up being added multiple times to the table resulting in the error above.

Do not use ID’s

The solution is rather simple, if you are adding terms to the site collection term group simply remove the ID’s from your term set and terms, and you are good to go:

<pnp:TermGroups>
 <pnp:TermGroup Name="{sitecollectiontermgroupname}">
   <pnp:TermSets>
     <pnp:TermSet Name="Wiki categories" Language="1033">
      <pnp:Terms>
        <pnp:Term Name="Prince 2" IsAvailableForTagging="true">
          <pnp:Terms>
            <pnp:Term Name="Closure" IsAvailableForTagging="true" />
            <pnp:Term Name="Discovery" IsAvailableForTagging="true" />
            <pnp:Term Name="Execution" IsAvailableForTagging="true" />
            <pnp:Term Name="Initiation" IsAvailableForTagging="true" />
          </pnp:Terms>
        </pnp:Term>
      </pnp:Terms>
     </pnp:TermSet>
   </pnp:TermSets>
 </pnp:TermGroup>
</pnp:TermGroups></pre>

 [1]: https://github.com/OfficeDev/PnP-Partner-Pack
 [2]: https://github.com/OfficeDev/PnP-Provisioning-Schema/blob/master/ProvisioningSchema-2015-05.md
 [3]: http://sadomovalex.blogspot.nl/2012/05/problem-with-creation-of-managed.html
Loading comments…