InfoPath Button: Create a New Site
This applies to SharePoint 2007, SharePoint 2010, and Office 365
In InfoPath, there’s a way to create a button that will create a new SharePoint site. First I’ll go through the steps on how to do it, and then the WHY, and how it could be useful.
- Open a new form in design mode.
- In the Fields pane on the right side of the form, create the following 4 fields:
- Title – text field
- Template – text field
- LCID – whole number – set the default value to 0
- Zone – text field
- Click to create a new data connection to submit data to a web service.
- For the URL to the web service, put the URL to your site, the site where you want to be able to click to create sub-sites, and make it look like this:
- For the operation, choose Create Workspace and click Next
- On the next screen, you have to map each of the listed parameters to the matching field that you already created.
Basically, click the little tree-looking box over to the right of “field or group” to pick the matching field.
- For the Title and templateName parameters, please check the box to “Submit data as a string”
- Finish out the wizard, all the defaults are fine.
Okay, so what does this do? It submits whatever’s in those 4 fields to create a new site. The person clicking the button does need to have access to be able to create sites.
Before we make it pretty, let’s test it. Drag the Title and the Template fields onto the surface of the form, so that we can enter text into them. Just make sure that LCID has a default value of zero, and zone isn’t important (not that I can tell anyway). So you can leave those last 2 fields alone.
Pretty generic form, I know. And where did all my instruction numbering go?… oh well.
In order to test the site creation, let’s stick a button on there. The button will have one action, to submit to that data connection that you just created.
I’m so excited, it’s almost time to push the button and watch magic happen. Go ahead and preview the form, or publish it and try it, it doesn’t matter, it will work either way. Fill out the fields like this:
No, you don’t have to call yours that, you can make the title whatever you want, but be sure and put that template value exactly the same, as STS#2. Hit the button! If you’re in preview mode, you’ll get the pop-up question about connecting to a data source and you can click Yes.
Now, go to your site, the one you entered in at step 4, and View All Site Content. There’s the test site, as a document workspace.
See, even though the web service is called “meetings”, it’s a little misleading because we can create any kind of site with the web service. We just need to know all those little codes for the different templates.
Next, back in design mode, let’s make it a little more user friendly. Right click on the template text box, and change the control to a drop-down list box. Add one manual choice to your list, setting the value as STS#2 and the display as “Document Workspace” like this:
All that is really needed now is the names of all the other templates that you want people to be able to pick from here. Here’s where Jeremy Thake wrote a list of them all. So, you could just manually enter them all in as drop-down choices. That way, people picking the template won’t have to know those codes.
Alright so that’s it, that’s the nitty gritty behind how to do it. But WHY do it?
This solution isn’t the prettiest, and it doesn’t seem like it would be necessary to fill out a form when you could just go to the site and create the sub-site from there, right?
Use this concept for a site provisioning solution. High level overview: Create this as a simple SharePoint form library or even just a list if you’re on 2010 enterprise. Set it up so that users fill out the form when they want to request a new site, just with all the basics, and this form will have to go through an APPROVAL before it gets to the person who will actually be clicking the button that submits to the web service. Once it’s gotten to the approval stage where it’s time to create the site, then the button will be available to click to create the site. The whole approval process could be done a slew of different ways, and the button could be on a certain view just for admins, or a certain hidden section, or it could just have a rule on it that says if approved = yes then it submits to that data connection.
You can learn more about approval processes in many of my other blog posts and videos, and at SPTechCon next week.
Also, big announcement…