In the previous blog here, we got an overview of the high level Architecture of a Complex Modern team site provisioning process. In this blog, we will look at the step 1 of the process – Create and Apply template process, in detail.
Before that, below are few links to earlier blogs, as a refresher, to prerequisties for the blog.

  1. Set up a Graph App to call Graph Service using App ID and Secret – link
  2. Sequencing HTTP Trigger Azure Functions for simultaneous calls – link
  3. Adding and Updating owners using Microsoft Graph Async calls – link

Overview
The Create and Apply Template process aims at the following
1. Create a blank modern team site using Groups Template (Group#0 Site template)
2. Apply the provisioning template on the created site.
Step 1 : Create a blank Modern team site
For creating a modern team site using CSOM we will use the TeamSiteCollectionCreationInformation class of OfficeDevPnP.  Before we create the site, we will make sure the site doesn’t already exist.

Note: There is an issue with the Site Assets library not getting intialized
when the site is created using the below code.
Hence, calling the EnsureSiteAssets library is necessary.

Step 2:  Apply the Provisioning Template

Note: The Apply template process is a long running process and takes from 60-90 min to complete
for a complex provisioning template with many site columns, content types and libraries.
In order to prevent the Azure function from timing out, it is required to host the Azure Function
using a App Service Plan instead of a Consumption plan so the Azure function
is not affected by the 10 min time out. 

For the Apply Provisioning Template process, use the below steps.
1. Reading the Template
It is important to note that the XMLPnPSchemaFormatter version (in the code below) must match the PnP version used to generate the PnP template. If the version is older, then set the XMLPnPSchemaFormatter to read from the older version. In order to find the version of the PnP Template, open the xml and look at the start of the file
PnPTemplateVersion

2. Apply the Template
For applying the template, we will use the ProvisioningTemplateApplyingInformation class of the OfficeDevPnP module. The ProvisioningTemplateApplyingInformation also has a property called HandlerToProcess which could be used the invoke the particular handler in the provisioning template process. Below is the code for the same.

After the apply template process is complete, since the flow will have timed out, we will invoke another flow to do the post process by updating a list item in the SharePoint list.
Conclusion
In this blog, we saw how we could create a modern team site and apply the template on it. The next blog we will finalize the process by doing site specfic changes after applying the template.

Category:
Application Development and Integration, Azure Platform, Communication and Collaboration, Office 365, PowerShell, SharePoint
Tags:
, , ,

Join the conversation! 1 Comment

  1. Where is assetContext coming from ?

Comments are closed.