SharePoint 2013 Workflows does not have any actions for creating a SharePoint sites, but you can solve this using the «call http web service» action and SharePoint REST API.
I wanted to give the users a form to order new sites in an easy way without being a site owner. I wanted to solve this using a SharePoint list with an attached workflow as a site order form. I am doing this proof of concept on my lab-site http://intranet.wingtip.com.
- Enable Workflow can use app permissions
- Create a list for ordering sites
- Create a workflow that creates a site when new item is created
- Grant full control permission to workflow (needed for workflow to create site)
Enable Workflow can use app permissions
- Under Settings button
- Select Site settings
- Select Manage site features
- Click Activate on Workflows can use app permissions
Create a list for ordering sites
- From your site – click Site Contents
- Click Add an app
- Click Custom list
- Give the new list a name like «Order project site» and click OK
We do not need any more fields for this proof of concept.
Create the workflow
- Click Order project site in the left menu to open your list
- Click List in the top menu to open list settings
Click Workflow Settings in the toolbar, then click Create a Workflow in SharePoint Designer
- Click Allow if you get a security warning
Enter a name for your workflow and click OK
- Rename the Stage to «Creating request header»
- Add a Build Dictionary action
Name the output variable «RequestHeader»:
- Click this to add variables to the dictionary
- Click Add
Add a string variable named content-type with the value application/json;odata=verbose and click OK
Add a new string variable named Accept with the value application/json;odata=verbose and click OK
- Click Stage in the toolbar to create a new step
- Rename the stage to Creating Request Body
- In Stage: Creating request header set Transition to stage to Go to Creating Request Body
- In Stage: Creating Request Body add a new Build Dictionary action
- Set output to a new variable MetaData
Add string variable named type with value SP.WebInfoCreationInformation
- Click OK to confirm all open dialog boxes
- Add a new Build dictionary action
- Set output to a new variable named RequestHeader
- Add these variables to RequestHeader:
|Url||String||Currentitem: TitleClick the fx button to add the Title of the current list item:|
|Title||String||Currentitem: TitleClick the fx button to add the Title of the current list item:|
|Description||String||Currentitem: TitleClick the fx button to add the Title of the current list item:|
|__metadata||Dictionary||Variable: MetaDataClick the fx button to add the previous created MetaData variable:|
- Click OK in all dialog boxes to save RequestHeader dictionary variable
- Add a new Build dictionary action
- Set output to new variable named RESTparameters
Add a variable named parameters type Dictionary
with the value of the previous created RequestHeader
- Click OK to close all open dialogs
- Add a new Stage and rename it to Creating Site
- Set Transition to stage in Creating Request Body to go to Creating Site
- In Stage: Creating Site add App Step
- In App step add Call http web service action
- Click this to add the web service URL
Enter the URL (use your own site and add /_api/web/webinfos/add to it) and select HTTP Post as HTTP method:
- Click OK when done
- Select the Call HTTP web service action
- Click Advanced Properies in the toolbar
Set RequestHeaders to variable RequestHeder and set RequestContent to variable RESTparameters:
- Click OK to close dialog
- In Stage: Creating Site set Transition to stage to go to End of Workflow
- Click Publish
Click OK in the next dialog:
Click Create site just below the Create site tab:
Check Start workflow automatically when an item is created
- Click Publish in the toolbar and confirm if you get any warning.
Grant full control permission to workflow
The following steps must be completed by a user that is a site owner. These actions require that a workflow has been published to the site.
- Click on the Settings button
- Go to Site Settings
- Under Users and Permissions, select Site app permissions
- Copy the client section of the App Identifier. This is the identifier between the last «|» and the «@» sign.
- Navigate to the Grant permission to an app page. This must be done by browsing to appinv.aspx in the site.
- Paste the client id in the App Id field and click Lookup
You will see complete details of the workflow app id.
- Paste the following Permissions Request XML to grant full control permission
- Click Create. You will then be asked for consent. Verify that you are asked for consent to give workflow full control of the site. If you do not see full control consent request it probably means that there was an error in the permissions request XML.
- Click Trust It
Your list should now create a new site each time an item is added.