SharePoint Site Script To Provision Calendar List And Add Attendees Column

In this article, we will learn how to provision calendar list with site design and site script concept and using this how to add Attendees site column to list. If you want to know the basics of site design and site script I would recommended you to read below links which will help you understand basic concept around site design and scripts.
We would be handling here one advanced scenario and it will cover the below use cases using site design and site script.
  • How to create custom content type
  • How to add site column to custom content type
  • How to create Calendar list.
  • How to add custom content type to Calendar list(this can be added to any list)
  • How to remove default Event content type from Calendar list.
Pre-requisites 
  1. First thing you would need is SharePoint Online management shell. In case you don't have installed, use this link to download. 
  2. You would need SharePoint Admin credentials to add Site design to your tenant.
If you have go through the above links or already know about site design and site script, you will  already be aware that we need to create site script as json file. Create a json file using your favourite editor.
 
Add below code to your .json file. 
  1. {  
  2.     "$schema""https://developer.microsoft.com/json-schemas/sp/site-design-script-actions.schema.json",  
  3.     "actions": [  
  4.       {  
  5.         "verb""createContentType",  
  6.         "name""Custom Event",  
  7.         "description""Custom event content type",  
  8.         "parentName""Event",  
  9.         "hidden"false,  
  10.         "subactions":  
  11.         [  
  12.             {  
  13.                 "verb""addSiteColumn",  
  14.                 "internalName""ParticipantsPicker",  
  15.                 "addToDefaultView"true  
  16.             }  
  17.         ]  
  18.     },  
  19.       {  
  20.         "verb""createSPList",  
  21.         "listName""My Calendar",  
  22.         "templateType": 106,  
  23.         "subactions": [  
  24.           {  
  25.             "verb""SetDescription",  
  26.             "description""Meetings calendar list for project management site"  
  27.           },  
  28.           {  
  29.             "verb""addContentType",  
  30.             "name""Custom Event"  
  31.           },  
  32.           {  
  33.             "verb""removeContentType",  
  34.             "name""Event"  
  35.          }  
  36.         ]  
  37.       }  
  38.       
  39.     ],  
  40.     "version": 1  
  41.   }  
The idea here is to add Attendees site column to calendar list and add this to default content type. As we cannot directly add site columns to existing content type, we will create a custom content type with base as 'Event' content type and then remove 'Event' content type from Calendar list.
 
Please note here InternalColumn name of Attendees site column is 'ParticipantsPicker' 
 
Above json is self explanatory, we are first creating custom content type with name 'Custom Event', and adding site column 'ParticipantsPicker' to this content type. Next action is to create SP List, and we are setting templateType as 106 which is template ID of Calendar list. Then we are adding our custom Content type and remove 'Event' content type.
 
Once we have script ready, let us start deployment on tenant.
 
First let us connect to our SharePoint Admin management url.
  1. $adminUPN="[email protected]"  
  2. $orgName="warnerbrothers"  
  3. $userCredential = Get-Credential -UserName $adminUPN -Message "Type the password."  
  4. Connect-SPOService -Url https://warnerbrothers-admin.sharepoint.com -Credential $userCredential  
This will ask you password in window, once connected we would be able to run any powershell commands.
 
Then lets us add our site script to tenant, run below command in management shell
  1. Get-Content 'D:\Projects\samples\SiteScriptDemo.json' `  
  2.      -Raw | `  
  3.      Add-SPOSiteScript `  
  4.     -Title "Calendar provision Site script"  
Once we run this, it will give below output, we need to copy site script id which will be used later.
 
SharePoint Site Script To Provision Calendar List And Add Attendees Column
 
Next thing to do is associate site script with site design, and run the below command. Please change GUID with output of above step.
  1. Add-SPOSiteDesign `  
  2.   -Title "Calendar Site design" `  
  3.   -WebTemplate "64" `  
  4.   -SiteScripts "42d2d3c4-f51b-47c2-bda3-9ef2qcc16ehd" `  
  5.   -Description "Creates calendar list and add Attendees column"  
SharePoint Site Script To Provision Calendar List And Add Attendees Column
 
Now we have out site design added to tenant, let us create a new SharePoint site collection and apply our site design to see output.
 
Go to SharePoint admin center
 
https://warnerbrothers-admin.sharepoint.com/_layouts/15/online/AdminHome.aspx#/home 
 
SharePoint Site Script To Provision Calendar List And Add Attendees Column
 
Once finished, browse the new site collection which is created, we should see new calendar list provisioned with Attendees column. We will see output in the below alternative way to apply site design.
 
SharePoint Site Script To Provision Calendar List And Add Attendees Column
 
Note
You can also choose to apply site design to existing site collection. Go to exisiting site collection, click on Gear icon on header, click on Site design.
 
SharePoint Site Script To Provision Calendar List And Add Attendees Column
Clicking on Apply, it will start applying our actions as below 
 
SharePoint Site Script To Provision Calendar List And Add Attendees Column
 
Once finished, refresh the site and go to Site contents. We can see 'My calendar' list created. Go to list setting to check if content types are created correctly.
 
SharePoint Site Script To Provision Calendar List And Add Attendees Column
Click on Add event in calender view and we can see the below form,
 
SharePoint Site Script To Provision Calendar List And Add Attendees Column
 
So that's it, we have seen how to create calendar list using site design and add Attendees column. We explored the below use case in this article.  
  • How to create custom content type
  • How to add site column to custom content type
  • How to create Calendar list.
  • How to add custom content type to Calendar list(this can be added to any list)
  • How to remove default Event content type from Calendar list. 
Hope you enjoyed reading...Happy coding..!!!