Skip to main content

Notifications

Community site session details

Community site session details

Session Id :

Adding a Document Set Content Type from Content type hub to a Library

SudeepGhatakNZ Profile Picture SudeepGhatakNZ 14,292 Most Valuable Professional

Introduction

SharePoint offers a wide range of features to streamline document management, one of which is Document Sets.

Document Sets allow you to group related documents together, making it easier to manage projects, contracts, or any other collections of files.

However, setting up and managing Document Sets across multiple sites and libraries can be time-consuming, especially in large organizations. This is where Power Automate comes into play. By automating the process of adding Document Set content types to SharePoint libraries, you can save time, reduce errors, and ensure consistency across your SharePoint environment.
In this blog, I’ll walk you through the steps to automate the process of adding a Document Set content type from the Content Type Hub to a SharePoint library using Power Automate. I’ll cover:
  1. Enabling the Document Set feature at the site level.
  2. Copying the Document Set content type from the Content Type Hub to your site.
  3. Adding the content type to a library.
  4. Creating a new Document Set in the library.
This blog will provide you with steps to automate Document Set management effectively using Power Automate.

What is Content Type Hub?

The Content Type Hub is a centralized repository for content types in SharePoint. It allows you to create, manage, and publish content types from a single location (usually a dedicated site collection) and then push those content types to other sites or site collections in your SharePoint environment. It offers various advantages
  1. The Content Type Hub allows you to manage content types in one place, ensuring consistency and reducing duplication. For example, you can define a Document Set content type once in the hub and reuse it across multiple sites or libraries.
  2. By publishing content types from the hub, you ensure that all sites and libraries use the same definitions for content types. This is especially important for organizations with multiple teams or departments that need to adhere to standardized document management practices.
  3. If you need to update a content type (e.g., add a new column or change a metadata field), you can make the change in the Content Type Hub and push the update to all subscribing sites. This eliminates the need to manually update content types in each site or library.
  4. Content types created in the hub can be reused across multiple sites, saving time and effort. For example, a Document Set content type designed for project documentation can be published to all project sites in your organization.
  5. Finally, The Content Type Hub helps enforce governance policies by ensuring that all sites use approved content types. This is critical for compliance with organizational or regulatory standards.
We will apply a document set to a library in two steps:
  1. Creating a document set in content type hub
  2. Using Power Automate to manage the publishing and document set use

STEP 1: Creating a document set in content type hub

Create a New Content Type:

  • The Content Type Hub is a dedicated site collection in your SharePoint environment. The URL is usually https://<your-tenant>.sharepoint.com/sites/contentTypeHub
Note: If you don’t have access to the Content Type Hub, contact your SharePoint administrator.
  • Click on the gear icon (⚙️) in the top-right corner of the page. Select Site information -> View all site settings.
  • In the Site Settings page, under the Web Designer Galleries section, click on Site content types.
                    
  • Click on the Create button at the top of the page. Fill in the following details:
    • Name: Give your content type a name (e.g., "Project Document Set").
    • Description: Add a description (optional but recommended).
    • Assign a Parent Content Type. Select Document Set from the Parent Content Type dropdown.
    • Under Parent Content Type from, select Document Content Types.
    • Group: Choose an existing group (e.g., "Custom Content Types") or create a new group to organize your content type.
  • Click OK to create the content type.
                             

Configure the Document Set Content Type


After creating the content type, you’ll be redirected to its settings page.
  • Scroll down to the Document Set section and click on Document Set settings.
  • Allowed Content Types: Add the content types that can be included in the Document Set (e.g., Word documents, Excel files, etc.).
  • Shared Columns: Define columns that will be shared across all documents in the Document Set.
  • Welcome Page Columns: Choose columns to display on the Document Set’s welcome page.
  • Welcome Page View: Customize the view of the welcome page.
  • Default Content: Upload default files or templates that will be automatically added to new Document Sets.
  • Click OK to save your settings.

                      
Publish the Content Type

  • On the content type settings page, click on Manage publishing for this content type.
                        
  • Click Publish to make the content type available to other sites.
If you make any changes to the content type in the future, you’ll need to republish it to propagate the changes to subscribing sites.
                

STEP 2: Using Power Automate to manage the publishing and document set use

Unfortunately, Power Automate doesn’t provide native actions to handle custom Document Sets directly. However, we can achieve this by leveraging SharePoint REST API calls within Power Automate. Here are the series of actions all usitizing Send HTTP request to SharePoint action in Power Automate

I will be referencing a variable that contains the root site url e.g. https://your-tenant.sharepoint.com/

1. Enable the Document Set Feature


Before you can use Document Sets, you need to enable the Document Set feature at the site level. Use the following endpoint:

Endpoint:
POST /_api/site/features/add
Headers:
{
  "accept": "application/json;odata=verbose",
  "content-type": "application/json;odata=verbose"
}
Body:
{
  "featureId": "3bae86a2-776d-499d-9db8-fa4cdc7884f8",
  "force": true
}


2. Get the Context Info


To make authenticated requests to SharePoint, you need to retrieve the Form Digest Value using the /_api/contextinfo endpoint.
Endpoint:
POST /_api/contextinfo
Headers:
{
  "accept": "application/json;odata=verbose"
}

3. Enable Content Types on the Library


Ensure that content types are enabled on the library where you want to add the Document Set.
Endpoint:
POST /_api/web/lists/getbytitle('Documents')/ContentTypes/enableContentTypes
Headers:
{
  "accept": "application/json;odata=verbose",
  "content-type": "application/json;odata=verbose",
  "X-RequestDigest": "<FormDigestValue>"
}
Body:
{
  "__metadata": {
    "type": "SP.List"
  },
  "ContentTypesEnabled": true
}


4. Copy the Document Set content type from the Content Type Hub to your site.

Endpoint:
POST
/_api/v2.0/sites/@{outputs('Compose_-_Customer')}/ContentTypes/addCopyFromContentTypeHub
Headers:
{
  "accept": "application/json;odata=verbose",
  "content-type": "application/json;odata=verbose",
  "X-RequestDigest": "<FormDigestValue>"
}
Body:
{
  "contentTypeId": "0x0120D520" // ID for the Document Set content type
}


5. Add the new Document Set in the library as an available content type.


Endpoint:

POST _api/web/lists/GetByTitle('Documents')/ContentTypes/AddAvailableContentType

Body:

{
"contentTypeId": "<Content Type ID>"
}

6. Create a New Document Set in the library

Finally, create a new Document Set in the library using the content type.
You can also use the out of the box Create item action. If you prefer the HTTP action, here it is

Endpoint:
POST /_api/web/lists/GetByTitle('Documents')/Items
Headers:
{
  "accept": "application/json;odata=verbose",
  "content-type": "application/json;odata=verbose",
  "X-RequestDigest": "<FormDigestValue>"
}

Body:
{
  "__metadata": {
    "type": "SP.Data.DocumentsItem"
  },
  "ContentTypeId": "0x0120D520",
  "Title": "New Document Set"
}


Final result




Comments