March 17, 2022

SharePoint Online - Content Types are not published to SharePoint Site from Content Type Hub

Introduction

We recently implemented an automated process to provision new Sites and apply a Site Design using Power Automate for a construction and engineering company based out of Massachusetts, United States. The Site Design included a process of creating new Lists and adding Content Types to the Lists. Here the Content Types are the ones that are published across all site collections from Content Type Hub. But in the recent past, Microsoft has switched content-type publishing approaches from a "Push Everywhere Model" to "Pull as Needed". So, what does this mean for us? To understand this, let's first look at how the old approach worked.

Problem Statement [Old Content Type Publishing Process]:

In the old process, the published content types in Content Type Hub were synced in all the site collections by Timer Job. There was no fixed sync duration - it took anywhere between a few hours to even 48 hours. This led to the issue of indefinitely waiting for a published content type to get synced to the site. Furthermore, unnecessary content types were also synced to the site collections.

To address these issues and to improve the performance and reliability of the sync, Microsoft has changed the way content type publishing worked. Let's now look at the new approach.

Resolution [New Content Type Publishing Process]:

The content type publishing will now sync to sites “on-demand”. Due to this, any solution dependent on waiting for a published content type to get automatically copied to all sites, stopped working. Thus, the users need to select or pull content types directly from the hub while adding them to lists and libraries. This approach solves the below issues:
  • Reduces the copying of published content types to sites where they are not desired
  • Adds published content types to a document library or list in a quicker way
  • Reduces unnecessary resource consumption to sync all published content types
Currently, there are three different ways available to programmatically add published content types to the desired destinations as below:
  • Site Scripts
  • PnP
  • CSOM

How to add published Content Types to any Site Collection programmatically using Site Scripts?

A new addContentTypesFromHub verb is available for use within SharePoint site script actions. This verb syncs content types from a content type hub to a specific site.
Example: 
 {  
  "verb": "addContentTypesFromHub",  
  "ids": ["0x01007CE30DD1206046628BAFD1C39A850120"]  
 }  
Note: Here ids can be an array of Content Type ID(s) that need to be synced.

Below is an example of Site Script to sync required Content Type(s) from a Content Type Hub to a specific site:
 {  
      "$schema": "https://developer.microsoft.com/json-schemas/sp/site-design-script-actions.schema.json",  
      "actions": [  
           {  
                "verb": "addContentTypesFromHub",  
                "ids": [  
                     "0x010100867E94987C6169418A7FB1B63A62AED5",  
                     "0x010100867E94987C6169418A7FB1B63A62AED501",  
                     "0x0120D520007912086EAFB3B24BA71AF502B342CDF8",  
                     "0x010100867E94987C6169418A7FB1B63A62AED502"  
                ]  
           }  
      ],  
      "version": 1  
 }  

We will explore PnP and CSOM approaches in the next part of this article.

Conclusion:

This is how we can change the approach to publish Content Type(s) from Content Type Hub to any SharePoint Site with a new approach. Hope this helps!

If you have any questions you can reach out our SharePoint Consulting team here.

1 comment: