Introduction: Site Scripts and Site Designs
Automating site provisioning in contemporary SharePoint Online environments is essential for ensuring consistency, upholding governance, and enhancing collaboration within an organization. Site Scripts and Site Designs are key tools that facilitate this process, helping to standardize site creation and maintain organizational standards.
What is Site Design?
What are Site Scripts?
- Create a new list or library (or alter the default one created with the site).
- Create the site columns, and content types, and configure other list settings.
- Set site branding properties such as navigation layout, header layout, and header background.
- Apply a theme and also Set a site logo.
- Triggering a Microsoft Flow.
- Include principals (users and groups) in SharePoint roles.
Why Use Site Scripts and Site Designs?
- Standardization & Consistency
- Ensures all sites follow the same structure, branding, and compliance requirements.
- Reduces manual errors by applying predefined settings.
- Automation & Efficiency
- Eliminates repetitive tasks such as manually creating lists, libraries, columns, or permissions.
- Reduces setup time for new SharePoint sites.
- Customization without Custom Code
- Site Scripts enable customization using JSON, eliminating the need for complex development efforts.
- It can be enhanced using PnP PowerShell, Power Automate, and various other SharePoint automation tools.
- Easy Updates & Scalability
- Site Designs can be updated centrally and re-applied to existing sites.
- Ideal for large organizations managing multiple SharePoint sites.
Creating a New Site Design and Site Script
- The first two actions create site columns.
- The third action creates a new content type in the site, named "User," and adds the two previously created site columns to this content type.
- The fourth action creates a new list in the SharePoint site, named "User Information," utilizing the newly created content type.
- The fifth action creates a new document library in the SharePoint site, named "User Documents", utilizing the created content type.
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/site-design.json#",
"actions": [
{
"verb": "createSiteColumn", //verb to create SiteColumn
"fieldType": "Text", //column type you want to create
"displayName": "First Name", //Column Display Name
"internalName": "FirstName",//Column Internal Name
"isRequired": false,
"id": "2d738560-6a73-4d1b-854e-8b195f9021eb", //Unique gui-id for your site column you can genrate it manuualy.
"group": "Test Site Columns" //give group name to identify
},
{
"verb": "createSiteColumn",
"fieldType": "DateTime",
"displayName": "Date of Birthday",
"internalName": "DateOfBirthday",
"isRequired": false,
"id": "da840479-d27e-490d-8624-cd1144ee07cc",
"group": "Test Site Columns"
},
{
"verb": "createContentType", //verb to create content type in site
"name": "User", //ContentType Name
"id": "0x0101009D1CB255DA76424F860D91F20E6C411800B609FEFDEFAA484299C6DE254182E666", //Unique content typeID
"description": "User content type containing personal information",
"parentId": "0x0101009D1CB255DA76424F860D91F20E6C4118", //Parent content type id
"hidden": false,
"subactions": [
// you can add your site columns as many as you can..
{
"verb": "addSiteColumn",
"internalName": "FirstName"
},
{
"verb": "addSiteColumn",
"internalName": "DateOfBirthday"
}
]
},
{
"verb": "createList", //Verb for Create a List
"listType": "GenericList", //List type you want to create Ex:GenericList(CustomList),Document Library,Task List etc...
"title": "User Information", //Title of your list
"description": "List to store user personal information.", //Desciption of your list
"templateType": 100, //Gave templtype for custom list it's 100, for document library it's 101
"contentTypesEnabled": true,
"subactions": [
{
"verb": "addContentType",
"name": "User"
}
]
},
{
//Creates a new Document Library
"verb": "createList",
"listType": "DocumentLibrary", //List type Document Library
"title": "User Documents",
"description": "Library for storing user-related documents.",
"templateType": 101,
"contentTypesEnabled": true,
"subactions": [
{
"verb": "addContentType",
"name": "User"
}
]
}
],
"version": 1
}
{
"verb": "createList",
"listType": "GenericList",
"title": "User Information",
"description": "List to store user personal information.",
"templateType": 100,
"subactions": [
{
"verb": "addField",
"fieldType": "Text",
"displayName": "First Name",
"internalName": "FirstName",
"isRequired": false
},
{
"verb": "addField",
"fieldType": "DateTime",
"displayName": "Date of Birthday",
"internalName": "DateOfBirthday",
"isRequired": false
}
]
}
How we can add Taxonomy Fields (Managed Metadata Fields) as Site Columns in Site-Script
{ "verb": "createSiteColumnXml", "schemaXml": "<Field ID=\"{"Unique Field GUID of your Managed Property"}\" Type=\"Note\" Name=\"DegreeTaxnomyField\" StaticName=\"DegreeTaxnomyField\" Group=\"Test Site Columns\" DisplayName=\"DegreeTaxnomyField\" ShowInViewForms=\"FALSE\" Required=\"FALSE\" Hidden=\"TRUE\" CanToggleHidden=\"TRUE\" />" }
$adminSite = "https://<<Your-TenantName>>-admin.sharepoint.com" Connect-PnPOnline -Url $adminSite -UseWebLogin $TermField = Get-PnPField -Identity "<<Your Term-Name>>" $fieldID = $TermField.TextField write-Host "Field Id: $fieldID"
- To create a taxonomy field as a site column in a site script, you need to define the field’s properties such as the Term Store, Term Set, and whether the field allows multiple selections.
- Below is an example of creating a TaxonomyFieldType (managed metadata field) as a site column:
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/site-design.json#", "actions": [ { "verb": "createSiteColumnXml", "schemaXml": "<Field ID=\"{Random unique Field-ID}\" Type=\"TaxonomyFieldType\" Name=\"Degree\" SourceID=\"http://schemas.microsoft.com/sharepoint/v3\" StaticName=\"Degree\" DisplayName=\"Degree\" Group=\"Test Site Columns\" ShowField=\"Term1033\" Required=\"FALSE\" EnforceUniqueValues=\"FALSE\" Mult=\"TRUE\"> \ <Default></Default> \ <Customization> \ <ArrayOfProperty> \ <Property> \ <Name>SspId</Name> \ <Value><<Your TaxonomyStoreSSPID>></Value> \ </Property> \ <Property> \ <Name>GroupId</Name> \ <Value><<Your TermStoreGroupID>></Value> \ </Property> \ <Property> \ <Name>TermSetId</Name> \ <Value><<DegreeTermSetID>></Value> \ </Property> \ <Property> \ <Name>TextField</Name> \ <Value>{<<Your Taxonomy Field ID>> // same as per the Your Hidden column's FieldID }</Value> </Property> \ <Property> \ <Name>AnchorId</Name> \ <Value>00000000-0000-0000-0000-000000000000</Value> \ </Property> \ <Property> \ <Name>IsPathRendered</Name> \ <Value>false</Value> \ </Property> \ <Property> \ <Name>IsKeyword</Name> \ <Value>false</Value> \ </Property> \ <Property> \ <Name>Open</Name> \ <Value>false</Value> \ </Property> \ </ArrayOfProperty> \ </Customization> \ </Field>" } ] }
- Type: TaxonomyFieldType – Defines that this field will be used as a managed metadata field.
- SourceID: Points to the SharePoint schema.
- ShowField: Defines the language to be used to show the term (e.g., Term1033 for English).
- Required: If the field is mandatory (FALSE means optional).
- Mult: Allows multiple terms to be selected from the Term Set (TRUE).
- Customization: Contains additional configuration for the taxonomy field, such as:
- SspId: The ID for the taxonomy store.
- GroupId: The ID of the Term Set group.
- TermSetId: The ID of the Term Set from the Term Store.
- TextField: The GUID of the field that will render the term text.
- IsPathRendered: Whether to show the term path (hierarchy).
- AnchorId: A default value (usually 00000000-0000-0000-0000-000000000000 for root terms).
- IsKeyword: Defines whether the term is a keyword.
- Open: Specifies whether the term set is open.
$adminSite = "https://<<Your-TenantName>>-admin.sharepoint.com" #Your Sharepoint admin site URL $siteScriptFile ="c:\scripts\site-script.json" #File path of JSON file. Connect-PnPOnline -Url $adminSite -UseWebLogin $content = [IO.File]::ReadAllText($siteScriptFile) $SPSiteScript = Add-PnPSiteScript -Content $content -Title "Test Site-Script" $SiteScriptId = $SPSiteScript.Id Write-Host "Site-Script ID: $SiteScriptId"
$adminSite = "https://<<Your-TenantName>>-admin.sharepoint.com" #Your Sharepoint admin site URL Connect-PnPOnline -Url $adminSite -UseWebLogin $SiteDesignDetails = Add-PnPSiteDesign -Title $SiteDesignTitle -SiteScriptIds $SPSiteScript.Id -Description $SiteDesignTitle -WebTemplate TeamSite Write-Host "Site Design is deployed successfully the GUID is:$($SiteDesignDetails.Id)"
$adminSite = "https://<<Your-TenantName>>-admin.sharepoint.com" #Your Sharepoint admin site URL Connect-PnPOnline -Url $adminSite -UseWebLogin # Run this Command If Your Site-Script has 30 Or less than 30 Actions Invoke-PnPSiteDesign -Identity "<<Site-DesigneeID>>" -WebUrl "<<Site url>>" # Run this Command If Your Site-Script has More than 30 actions Add-PnPSiteDesignTask -SiteDesignId "<<Site-DesigneeID>>" -WebUrl "<<Site url>>"
Summary
This blog post discusses how Site Scripts and Site Designs in SharePoint Online simplify the site provisioning process by automating the creation of lists, libraries, content types, and branding. These tools help maintain consistency and governance across sites.
Site Designs specify the configurations for a site, while Site Scripts—created using JSON—execute specific actions. These actions can include adding site columns, applying themes, and integrating Power Automate. By using these tools, organizations can reduce manual effort, enforce standardization, and achieve customization without the need for complex coding.
No comments:
Post a Comment