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”
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/site-design-script-actions.schema.json",
"actions": [
{
"verb": "createSiteColumn",
"fieldType": "Text",
"internalName": "TrainingID",
"displayName": "Training ID",
"group": "Additional 365 Evergreen site columns"
},
{
"verb": "createSiteColumn",
"fieldType": "DateTime",
"internalName": "TrainingDate",
"displayName": "Training Date",
"group": "Additional 365 Evergreen site columns"
},
{
"verb": "createSiteColumn",
"fieldType": "Text",
"internalName": "EmployeeName",
"displayName": "Employee Name",
"group": "Additional 365 Evergreen site columns"
},
{
"verb": "createSiteColumn",
"fieldType": "Text",
"internalName": "Department",
"displayName": "Department",
"group": "Additional 365 Evergreen site columns"
},
{
"verb": "createSiteColumn",
"fieldType": "Text",
"internalName": "TrainingCourse",
"displayName": "Training Course",
"group": "Additional 365 Evergreen site columns"
},
{
"verb": "createSiteColumn",
"fieldType": "Text",
"internalName": "Trainer",
"displayName": "Trainer",
"group": "Additional 365 Evergreen site columns"
},
{
"verb": "createSiteColumn",
"fieldType": "Text",
"internalName": "Location",
"displayName": "Location",
"group": "Additional 365 Evergreen site columns"
},
{
"verb": "createSiteColumn",
"fieldType": "Number",
"internalName": "DurationHours",
"displayName": "Duration (hours)",
"group": "Additional 365 Evergreen site columns"
},
{
"verb": "createSiteColumn",
"fieldType": "Choice",
"internalName": "CompletionStatus",
"displayName": "Completion Status",
"group": "Additional 365 Evergreen site columns",
"choices": [
"Completed",
"Pending",
"In Progress"
]
},
{
"verb": "createSiteColumn",
"fieldType": "Choice",
"internalName": "CertificateIssued",
"displayName": "Certificate Issued",
"group": "Additional 365 Evergreen site columns",
"choices": [
"Yes",
"No"
]
},
{
"verb": "createSiteColumn",
"fieldType": "Note",
"internalName": "Notes",
"displayName": "Notes",
"group": "Additional 365 Evergreen site 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