Skip to content

Commit 53ae631

Browse files
committed
2 parents 2bd776b + a7a08c9 commit 53ae631

File tree

3 files changed

+176
-16
lines changed

3 files changed

+176
-16
lines changed
Loading
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
---
2+
title: Using site designs and Microsoft Flow to track site creation requests
3+
description: Invoke a Microsoft Flow using the site script triggerFlow action to capture the site creation event and build a site directory. This tutorial is intended to illustrate a simple example of using site designs and Microsoft Flow.
4+
ms.date: 08/21/2018
5+
---
6+
7+
# Calling Microsoft Flow from a site script
8+
9+
Site designs are a powerful extensibility mechanism for customizing - and standardizing - the look and feel of your site collections. One of the script actions - **triggerFlow** - can be used to call custom solutions to apply configurations we don't support natively. Flow can also be used for business automation - in this case, used with site designs to track the creation of sites!
10+
11+
This article describes how to build a simple site directory using a site design and Microsoft Flow. Whenever a site is created using this site design, details of the site are captured and written to a list.
12+
13+
The steps in this article illustrate the following components:
14+
15+
- A SharePoint list
16+
- A site design and a site script
17+
- Microsoft Flow
18+
19+
You'll first create the SharePoint list and then it will be referenced in your Flow - which will be triggered by the site design which is applied after the site is created.
20+
21+
## Create your site directory list
22+
23+
You need to first set up the list that will be used to record all the sites created using this site design.
24+
25+
1. Select a site collection to host your list.
26+
27+
2. Create a new list named "Site Directory"
28+
29+
3. Configure the following fields:
30+
31+
- webUrl (Hyperlink or Picture)
32+
- webDescription (Single line of text)
33+
- creatorName (Single line of text)
34+
- creatorEmail (Single line of text)
35+
- createdTimeUTC (Single line of text)
36+
37+
38+
## Create the Flow
39+
40+
In order to capture the site creation event and create the corresponding list item, you need to create a Flow - which can then be referenced in your site design's site script:
41+
42+
1. Go to the [Microsoft Flow](https://flow.microsoft.com) site, sign in, and choose **Create from Blank** at the top of the page.
43+
44+
2. Choose **Search hundreds of connectors and triggers** to select your trigger.
45+
46+
3. Search for **Request**, and then choose **Request - When an HTTP Request is received**.
47+
48+
4. Enter the following JSON as your request body:
49+
50+
```
51+
{
52+
"type": "object",
53+
"properties": {
54+
"webUrl": {
55+
"type": "string"
56+
},
57+
"parameters": {
58+
"type": "object",
59+
"properties": {
60+
"event": {
61+
"type": "string"
62+
},
63+
"product": {
64+
"type": "string"
65+
}
66+
}
67+
},
68+
"webDescription": {
69+
"type": "string"
70+
},
71+
"creatorName": {
72+
"type": "string"
73+
},
74+
"creatorEmail": {
75+
"type": "string"
76+
},
77+
"createdTimeUTC": {
78+
"type": "string"
79+
}
80+
}
81+
}
82+
```
83+
84+
5. Select **+ New Step**, and choose **Add an action**.
85+
86+
6. Search for **Create item**, and select **SharePoint - Create item**.
87+
88+
7. Enter the site address where the list above was created.
89+
90+
8. Select the "Site Directory" list you created in the previous step.
91+
92+
9. Enter a value for the **Title** field - this will be the same value for each list item, for example "Contoso Travel: New Project Site Created".
93+
94+
10. For each field in your list form, add the corresponding element from the Dynamic Content picker. When you are done your action should look something like this:
95+
96+
![Screenshot of a flow named 'When an HTTP request is received', showing the URL, Request body, Queue name, and Message fields](images/site-directory-flow-configuration.png)
97+
98+
11. Choose **Save Flow**. This generates the HTTP Post URL that you will need to copy for your site script triggerFlow action.
99+
100+
14. Choose the first step in your flow ('When an HTTP request is received') and copy the URL.
101+
102+
15. Save your flow.
103+
104+
## Create the site design
105+
106+
1. Open PowerShell and make sure that you have the latest [SharePoint Online Management Shell](https://www.microsoft.com/en-us/download/details.aspx?id=35588) installed.
107+
108+
2. Connect to your tenant using **Connect-SPOService**.
109+
110+
```powershell
111+
Connect-SPOService -Url https://[yourtenant]-admin.sharepoint.com
112+
```
113+
114+
3. Now you can get the existing site designs.
115+
116+
```powershell
117+
Get-SPOSiteDesign
118+
```
119+
120+
<br/>
121+
122+
To create a site design, you first need to create a site script. A site design is a container that refers to one or more site scripts.
123+
124+
1. Copy the following JSON code to your clipboard and modify it. Set the `url` property to the value that you copied when you created the flow. The URL looks similar to the following:
125+
126+
`https://prod-27.westus.logic.azure.com:443/workflows/ef7434cf0d704dd48ef5fb6...oke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun`
127+
128+
```json
129+
{
130+
"$schema": "schema.json",
131+
"actions": [
132+
{
133+
"verb": "triggerFlow",
134+
"url": "[paste the workflow trigger URL here]",
135+
"name": "Record site creation event",
136+
"parameters": {
137+
"event":"site creation",
138+
"product":"SharePoint Online"
139+
}
140+
}
141+
]
142+
}
143+
```
144+
145+
2. Select the JSON again and copy it again to your clipboard.
146+
147+
3. Open PowerShell and enter the following to copy the script into a variable and create the site script:
148+
149+
```powershell
150+
$script = Get-Clipboard -Raw
151+
Add-SPOSiteScript -Title "Site Script to record site creation event" -Content $script
152+
Get-SPOSiteScript
153+
```
154+
155+
4. You will see a list of one or more site scripts, including the site script you just created. Select the ID of the site script that you created, and copy it to the clipboard.
156+
157+
5. Use the following command to create the site design:
158+
159+
```powershell
160+
Add-SPOSiteDesign -Title "Record site creation" -Description "The creation of this site will be recorded in the site directory list" -SiteScripts [Paste the ID of the Site Script here] -WebTemplate "64"
161+
```
162+
> [!NOTE]
163+
> The **Add-SPOSiteDesign** cmdlet associates the site design with the Team site. If you want to associate the design with a Communication site, use the value "68".
164+
165+
## Verify the results
166+
167+
To test the results, create a new site. In your SharePoint tenant, select **SharePoint** > **Create Site** > **Team Site**.
168+
169+
Your new site design should show up as a design option. Notice that the site design is applied after the site is created. If you configured it correctly, your flow will be triggered. You can check the run history of the flow to verify that it ran correctly. Note that the footer might not show up immediately; if you don't see it, wait a minute and reload your site to check again.
170+
171+
172+
## See also
173+
174+
- [SharePoint site design and site script overview](site-design-overview.md)
175+
- [Calling the PnP provisioning engine from a site script](site-design-pnp-provisioning.md)
176+

docs/declarative-customization/site-design-trigger-flow.md

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)