Site scripts and the content type hub

Introduction

In this post, I will walk you through the process of creating a content type for SharePoint Online and publishing it to the content type hub for use across all site collections.

NB: You’ll need to be a SharePoint administrator to publish to the hub

What is the content type hub?

Each SharePoint site uses content types, a site comes pre-populated with a set of content types and a set of lists and libraries that use these content types. You can also create your own content types, either being a site content type or list content type, but you can also consume content types from a central location: the content type hub.

Building the content type

In this section, we’ll look at how you can use a combination of JSON and PowerShell to create site columns and content types and then publish them to the content type hub.

The beauty of this approach is, once you’ve created the necessary assets, they become reusable. That means you can edit the code to easily create new content types and even publish content types to multiple tenants.

Create the site columns

The below JSON can be used to create the site coumns we want to use in the training request content type. Create a new file (preferably a JSON file in Visual Studio Code), copy the code, paste and save.

Things to note about the column structure;

  • internalName should not include spaces
    • including spaces can cause issues later
  • group
    • Default is “Custom Columns”, but I have decided to use a group of my own “Additional 365 Evergreen Columns”

Create content type

Next, we can add add below code to create the content type

Add the site columns

Add the below

No Responses

Leave a Reply

Your email address will not be published. Required fields are marked *