Step 1: Create the Workflow Initiation Form in SharePoint Server 2010 (ECM)
Applies to: SharePoint Server 2010
By using Microsoft InfoPath 2010, you can create workflow forms that run in Microsoft Office 2010 client applications—such as Microsoft Excel 2010, Word 2010, PowerPoint 2010, and InfoPath Forms Services itself—and also in a web browser.
The steps in this procedure follow procedures that are described in How to: Design InfoPath Workflow Forms (ECM).
This procedure assumes that you are familiar with adding controls to an InfoPath 2010 form and configuring those controls.
To create the workflow initiation form
Open InfoPath Designer 2010. Under Popular Form Templates, select Blank Form, and then click Design Form.
On the form, add the following controls to capture the information that the workflow requires:
On the form surface, type Assign Task To:, press Enter to insert a new line, then click the Text Box control in the ribbon control collection to insert a text box onto the form, below the label. On the form, right-click the text box control you just added, and select Text Box Properties. For Field Name, type assignee, and then click OK.
Type Instructions:, press Enter, and then add another text box control onto the form. On the form, right-click the text box control, and select Text Box Properties. For Field Name, type instructions, and then click OK.
Type Comments:, press Enter, and then add another text box control onto the form. Right-click the text box control, and then select Text Box Properties. For Field Name, type comments, and then click OK.
Insert a button control onto the form. Right-click the button control, and then select Button Properties. On the General tab, for Label, type submit, and then click OK.
When you are finished, your form should resemble the following figure.
Notice that the text fields are named assignee, instructions, and comments. These text field names will be used later in this walkthrough to populate the SPWorkflowActivationProperties that are called from the onWorkflowActivated activity in the workflow code. When the form submits its data to SharePoint Server 2010, SharePoint Server 2010 starts a new workflow instance and adds these custom properties to the SPWorkflowActivationProperties object as name and value pairs. Your workflow code can then retrieve the data by accessing those name and value pairs.
For more information, see How to: Design a Workflow Form to Use Association and Initiation Data in SharePoint Server 2010 (ECM).
At this point, you should rename the fields collection with a unique name. To do this, on the Fields pane, right-click myFields, and then select Properties. In the Field or Group Properties dialog box, under the Properties on the Data tab, change the Name field to InitiationForm.
Later in this procedure, you will extract the schema from this form to create a schema (.xsd) file. This schema then becomes the basis for the class you will create and reference in the workflow activity code. The form fields collection name will become the name of the root element of the schema file. The class that is generated from the schema file, in turn, will have the same name as the schema file root element.
Specifying a unique name for the field collection helps ensure that the class that is generated from the form schema file also has a unique name. This is especially important when you are programming a workflow that deserializes multiple forms.
Add two rules to the Submit button. The first rule will submit the form information to the hosting environment (in this case, SharePoint Server 2010); the second rule closes the form when the user clicks Submit.
Select the Submit button.
On the ribbon, click Add Rule, and in the drop-down list, point to When This Button Is Clicked, and then select Submit Data.
In the Rule Details dialog box, you must add a data connection. Click Add to start the Data Connection Wizard.
In the Data Connection Wizard, ensure that the Create a new connection to and Submit data radio buttons are selected, and then click Next.
Under How do you want to submit your data?, select To the hosting environment, such as an ASP.NET page or a hosting application, and then click Next.
Ensure that the Set as the default submit connection check box is selected. Click Finish to close the Data Connection Wizard. Click OK to close the Rule Details dialog box.
At this point, the Rules pane should appear with the information that pertains to the rules that you have set for the selected button.
Add another rule to the Submit button:
Click Add Rule on the ribbon again, point to When This Button Is Clicked, and then select Close Form.
Click OK to exit from the various dialog boxes.
Publish the form:
Save the form.
In InfoPath Designer 2010, click File, and then click Publish. Click SharePoint Server.
In the Publishing Wizard, select the SharePoint Forms Library where you want to publish your workflow form, rename the file InitiationForm, and save it as an InfoPath Web Browser Form Template. Click Save.
In the Publishing Wizard, enter the location of your SharePoint site, and then click Next.
Select Form Library, and then click Next.
At this point, you can choose to create a new Form Library. When you are finished, click Next
Now you must indicate which fields in your form will be available for SharePoint to process and how they map to the column names in the library.
Select the first field under Field to display as column, and assign it a column name.
Generally, you will use the (This form library) option to select columns, because the Publishing Wizard is providing a list of those columns available from the list that you are publishing to.
Repeat for each column you want to map. Click Next when finished.
Verify your form information, and then click Publish. Click Close.
Generate a new class file based on the form schema (.xsd) file.
Click File, and then click Publish. Click Export Source Files. Browse to the location where you want to save the form source files, and then click OK.
InfoPath saves a collection of form source files, including the schema file, to the specified location. The form schema file is always named myschema.xsd.
Use the Microsoft .NET Framework 2.0 command-line tool—xsd.exe—to generate a new class file from the form schema.
Open a Visual Studio Command Prompt window. Click the Start button, select All Programs, select Microsoft Visual Studio, select Visual Studio Tools, and then click Visual Studio Command Prompt.
Navigate to the location of the form schema (.xsd) file, and then, depending on the language you are using to develop your workflow, run the following command:
xsd myschema.xsd /c /l:CS BuiltInActiveXControls.xsd
xsd myschema.xsd /c /l:VB BuiltInActiveXControls.xsd
This command generates a new class file based on the form schema. The file is created with the same name as the schema file. In this case, it would be myschema_builtinactivexcontrols.cs.