|
1 |
| -# Get started creating site designs |
| 1 | +# Get started creating site designs and site scripts |
2 | 2 |
|
3 | 3 | Build site designs to provide reusable lists, themes, layouts, pages, or custom actions so that your users can quickly build new SharePoint sites with the features they need. In this article you'll build a simple site design that adds a SharePoint list for tracking customer orders. Then you'll use the site design to create a new SharePoint site with the custom list.
|
4 | 4 |
|
5 |
| -## Create the JSON script |
| 5 | +This article shows how to use SharePoint PowerShell cmdlets to create site scripts and site designs. You can also use CSOM and REST APIs to perform the same actions. The corresponding CSOM and REST calls are shown for reference in each step. |
| 6 | + |
| 7 | +## Create the site script in JSON |
6 | 8 |
|
7 | 9 | A site design is a collection of actions that SharePoint will run when creating a new site. Actions describe changes to apply to the new site, such as creating a new list, or applying a theme. The actions are specified in a JSON script. The JSON script is a list of all actions to apply. When a script runs, SharePoint completes each action in the order listed.
|
8 | 10 |
|
9 |
| -EAch action is specified by the "verb" value in the JSON scipt. Also, actions can have subactions which are also "verb" values. In the JSON below, the script specifies to create a new list named Customer Tracking, and then subactions set the description and add several fields to define the list. |
| 11 | +Each action is specified by the "verb" value in the JSON scipt. Also, actions can have subactions which are also "verb" values. In the JSON below, the script specifies to create a new list named Customer Tracking, and then subactions set the description and add several fields to define the list. |
| 12 | + |
| 13 | +1. Download and install the [SharePoint Online Management Shell](https://www.microsoft.com/en-us/download/details.aspx?id=35588). If you already have a previous version of the shell installed, uninstall it first and then install the latest version. |
| 14 | +1. Follow the instructions at [Connect to SharePoint Online PowerShell](https://technet.microsoft.com/en-us/library/fp161372.aspx) to connect to your SharePoint tenant. |
| 15 | +1. Create and assign the JSON that descripts the new script to a variable as shown in the PowerShell code below. |
10 | 16 |
|
11 |
| -1. Go to the home page of the SharePoint site you are using for development. You have to be at the home page, not inside a site or you'll receive an authentication error. |
12 |
| -1. Use the developer tools of your browser to open the console window. |
13 |
| -1. Enter the JSON script below |
| 17 | +> ![NOTE] |
| 18 | +> You can also specify the script in a CSV format. (TBD link to more info on CSV example) |
14 | 19 |
|
15 |
| -```javascript |
16 |
| -var site_script = { |
| 20 | +```powershell |
| 21 | +$site_script = @' |
| 22 | +{ |
17 | 23 | "$schema": "schema.json",
|
18 | 24 | "actions": [
|
19 | 25 | {
|
@@ -58,60 +64,42 @@ var site_script = {
|
58 | 64 | "bindata": { },
|
59 | 65 | "version": 1
|
60 | 66 | }
|
| 67 | +'@ |
61 | 68 | ```
|
62 | 69 |
|
63 |
| -## Create a function to submit REST API requests |
64 |
| - |
65 |
| -You'll need to interact with the site design REST API. You can use the following function to submit REST request. |
66 |
| - |
67 |
| -- In the console window enter the following **restRequest** function. |
68 |
| - |
69 |
| -```javascript |
70 |
| -function restRequest(url,params) { |
71 |
| - var req = new XMLHttpRequest(); |
72 |
| - req.onreadystatechange = function () |
73 |
| - { |
74 |
| - if (req.readyState != 4) // Loaded |
75 |
| - return; |
76 |
| - console.log(req.responseText); |
77 |
| - }; |
78 |
| - req.open("POST",url,true); |
79 |
| - req.setRequestHeader("Content-Type", "application/json;charset=utf-8"); |
80 |
| - req.setRequestHeader("ACCEPT", "application/json; odata.metadata=minimal"); |
81 |
| - req.setRequestHeader("x-requestdigest", _spPageContextInfo.formDigestValue); |
82 |
| - req.setRequestHeader("ODATA-VERSION","4.0"); |
83 |
| - req.send(params ? JSON.stringify(params) : void 0); |
84 |
| -} |
| 70 | +The previous script will create a new SharePoint list named Customer Tracking. It will set the description, and also add four fields to the list. |
| 71 | + |
| 72 | +## Add the site script |
| 73 | + |
| 74 | +Each site script must be registered in SharePoint so that it is available to. Add a new site design by using the **Add-SPOSiteScript** command. The following example shows how to add the JSON script described previously. |
| 75 | + |
| 76 | +```powershell |
| 77 | +C:\> Add-SPOSiteScript -Title "Create customer tracking list" -Content $site_script -Description "Creates list for tracking customer contact information" |
85 | 78 | ```
|
86 | 79 |
|
87 |
| -## Register the site design |
| 80 | +After running the command you will get a result that lists the site script **ID** of the added script. Keep track of this ID somewhere because you will need it later when you create the site design. |
88 | 81 |
|
89 |
| -Each site design needs to be registered in SharePoint so that it is available to users. You register a new site design by calling the **CreateSiteDesign** REST API. The following example shows how to register the JSON script that creates a new list. |
| 82 | +The REST API to add a new site script is **CreateSiteScript**. (TBD add CSOM link) |
90 | 83 |
|
91 |
| -1. Enter the following JavaScript code into your browser's console window. |
92 |
| - |
93 |
| - ```javascript |
94 |
| - restRequest("/_api/Microsoft.Sharepoint.Utilities.WebTemplateExtensions.SiteScriptUtility.CreateSiteScript(Title=@title)?@title='customer orders'", site_script); |
95 |
| - ``` |
96 |
| - |
97 |
| -1. The call returns a JSON response containing a site script **ID**. Copy this somewhere so you can use it later. |
| 84 | +## Create the site design |
98 | 85 |
|
99 |
| -## Attach the site design to a template |
| 86 | +Next you need to create the site design. The site design will appear in a drop down list when someone creates a new site from one of the templates. It can run one or more site scripts that have already been added. |
100 | 87 |
|
101 |
| -Site designs are only used with the two templates provided with SharePoint. Team site, or communication site. Call the CreateSiteDesign REST API to create the site. It takes the following parameters |
102 |
| -webTemplate: 64 for Team site and 68 for Communication site. |
| 88 | +- Run the following command to add a new site design. Replace \<ID\> with the site script ID from when you added the site script. |
103 | 89 |
|
104 |
| -```javascript |
105 |
| -restRequest("/_api/Microsoft.Sharepoint.Utilities.WebTemplateExtensions.SiteScriptUtility.CreateSiteDesign", {info:{Title:"customer orders", Description:"Tracks customer orders", SiteScriptIds:["SiteScriptID from previous response"], WebTemplate:"64", IsDefault: false}}); |
| 90 | +```powershell |
| 91 | +C:\> Add-SPOSiteDesign -Title "Contoso customer tracking" -WebTemplate "64" -SiteScripts "<ID>" -Description "Tracks key customer data in a list" |
106 | 92 | ```
|
107 | 93 |
|
108 |
| -The JSON response will contain an **ID** that you can use later to remove the registration if you want. |
| 94 | +The previous command creates a new site design named Contoso customer tracking. The -WebTemplate value selects which base template to associate with. The value "64" indicates Team site template, and the value "68" indicates the communication site template. |
| 95 | + |
| 96 | +The JSON response will display the **ID** of the new site design. You can use in subsequent commands to update or modify the site design. |
109 | 97 |
|
110 |
| -is default is whether it gets used by default |
| 98 | +The REST API to add a new site design is **CreateSiteDesign**. (TBD add CSOM link) |
111 | 99 |
|
112 | 100 | ## Use the new site design
|
113 | 101 |
|
114 |
| -Now that the registrations are completed you can use it to create new sites. |
| 102 | +Now that you've added a site script and site design, you can use it to create new sites. |
115 | 103 |
|
116 | 104 | 1. Go to the home page of the SharePoint site you are using for development.
|
117 | 105 | 1. Choose **Create site**.
|
|
0 commit comments