How To: Add SharePoint Workflow Support to an InfoPath Form

Document workflow is a feature of Windows SharePoint Services 3.0 that enables you to define a workflow and use it in a SharePoint document library. Built-in workflow scenarios, such as routing a document for approval or collecting feedback about a document are common workflow templates that can be customized to fit your particular needs. Any Office document can have a workflow associated with it, but Microsoft Office InfoPath 2007 form templates can also be designed in a way that allows workflow information to be incorporated in the InfoPath form template.

Access to a server running Windows SharePoint Services 3.0 or Microsoft Office SharePoint Server 2007 is required in order to complete the steps below.

Create and Publish a Form Template

To begin, create a form template and publish it to a server running Windows SharePoint Services 3.0. During the publishing process, select the option to create a new document library in the InfoPath Publish a Form wizard. This library will be used in the next section for creating a new workflow.

Create a Workflow in the Form Library

For the purposes of this exercise, you will create a workflow based on the Collect Feedback built-in workflow.

  1. In the new SharePoint library, click Settings, then click Form Library Settings.
  2. In the Permissions and Policies section, click Workflow settings. If you do not see this section, you need to request permission to modify the SharePoint site from your system administrator.
  3. Click Add a workflow.
  4. In the Select a workflow template list box, click Collect Feedback.
  5. Type a name for the workflow, such as "Get Feedback".
  6. Make sure the Start this workflow when a new item is created box is unchecked, then click Next.
  7. On the next page, in the Default Workflow Start Values section, click the Approvers button.
  8. In the Add Recipients dialog box, search for and add one or more approvers. For the purposes of this exercise, add yourself as one of the approvers, and click OK.
  9. On the Customize Workflow page, click OK.
  10. Your new workflow now appears under the Workflow Name section of the Change Workflow Settings page.
  11. Using the navigation links above the page title, navigate back to your library.

Create a New Form

Since the workflow was established to begin when a new item is created in the SharePoint library, create a new form to begin the workflow.

  1. To create a new form, click New in the SharePoint library.
  2. Fill in any required values and save the form, giving it a unique name.
  3. On the File menu, click Start Workflow.
  4. In the Start New Workflow dialog box, click the Start link. After the dialog refreshes, fill in any necessary information, then click the Start button.
  5. In the Message Bar, which appears just below the InfoPath toolbars and reads Workflow Task, click Edit this task button. Note that you will see this immediately because you added yourself as an approver. Other users will receive an e-mail notifying them of the task, and will see the Message Bar when they open the form template. If you have multiple workflow tasks related to the document, the Edit this task button becomes the View Workflow Tasks button.
  6. Modify the workflow, clicking either the Save or Send Feedback buttons.
  7. In the browser, notice that there is a new column in the list corresponding to the name of your workflow. Also notice the value indicating that the workflow is in progress on the form you just created. If you do not see this, refresh your browser.
  8. As an alternative to modifying the workflow in InfoPath, you can click on the form workflow status link in the browser to view details about the workflow.
  9. In the Tasks section of the Workflow Status page, click the drop down arrow and click Edit Item.

Modify the Workflow

Once a workflow has been initiated on a document it can be modified on an ad-hoc basis. Click on the workflow status link to change the workflow that is in progress, and options such as adding a new approver or cancelling the workflow may be available depending on how the workflow was structured.

Writing Workflow values to the Form

In addition to having workflow metadata associated with an Office document, InfoPath documents can contain workflow information in the form itself. This is enabled by querying the SharePoint list for the status of the workflow, then mapping the status value to a text value in the form. To enable this in the example form template, add a data connection to the SharePoint list, then add multiple expression boxes that represent the workflow status and hide them with conditional formatting when they don't apply.

Add a Data Connection to the SharePoint List

  1. Open the form template is design mode.

  2. On the Tools menu, click Data Connections.

  3. In the Data Connections dialog box, click the Add button.

  4. In the Data Connection Wizard, create a new connection to receive data, and click Next.

  5. Click SharePoint library or list from the Select the source of your data step, and click Next.

  6. Type the URL of the SharePoint server where you previously published your form template, and click Next.

  7. In the Select a list or library column, select the SharePoint library where you published the form template, and click Next.

  8. In the Select Fields list, uncheck every item except for the workflow status field, which is the name of the workflow.

  9. Check the Include data for the active form only, and click Next.

    ** Important **  If you don't check the box, values for every document in the library will be returned.

  10. Click Finish.

  11. In the Data Connections dialog box, click Close.

Add Expression boxes to show workflow status

Though you could now add the field returned from the SharePoint data connection to the form view, it would not mean much to users because SharePoint returns values to represent workflow status, not the status you see in the browser. The following table lists the values and what they mean.

Workflow value Status
0 Not Started
1 Failed On Start
2 In Progress
3 Error Occurred
4 Stopped By User
5 Completed
15 Canceled
Bb251016.vs_note(en-us,office.12).gif  Note
To confirm a value and its associated Status, add the workflow field to the form template view, change the workflow status of a form in the form library or in InfoPath, then close and re-open it in InfoPath. The workflow value will appear in the control bound to the workflow field.

Use the following procedure to add expression boxes to the form for each of these values, and conditionally hide each expression box based on the workflow field returned in the data connection.

  1. Type "Workflow Status:" where you want to show the workflow status in the view.
  2. Place an Expression Box control from the Controls task pane to the right of the text.
  3. In the Insert Expression Box dialog box, type "Not Started" with quotations, and click OK.
  4. Double-click the expression box, and click the Conditional Formatting button on the Display tab.
  5. On the Conditional Formatting dialog box,click the Add button .
  6. In the If this condition is true section, click the first drop-down box, and click Select a field or group.
  7. In the Select a field or group dialog box, change the data source to the SharePoint data connection.
  8. Click to expand the field list until you see the workflow status field, which is the name of the workflow, and click OK.
  9. In the Conditional Formatting dialog box, click the second drop-down box and select is not equal to.
  10. In the third drop-down box, select Type a number and enter the value of 0 (zero).
  11. Click the And button to add a second condition.
  12. Repeat steps six through eight to select the workflow status field.
  13. In the second drop-down box select is present.
  14. Check the Hide this control box and click OK three times to dismiss all dialog boxes.

Repeat the steps above, adding a new Expression Box control for each workflow status in the table. You can add and resize the expression boxes so they are next to each other or even slightly overlapping. Because only one status will be displayed at a time, they will always appear next to the "Workflow Status:" text.

Bb251016.vs_note(en-us,office.12).gif  Note
Two conditions are also necessary for the other values in the table. The first condition is if the workflow status field is not equal to the workflow value corresponding to the status you entered in quotations in the expression box, then hide the control. The second condition is if the workflow status field is not present, then hide the control. These conditions are separated with an or instead of the default and when you click the And button to add a second condition.

Once you are finished with adding the expression boxes, save and re-publish the form template to the SharePoint library with the same options as before. Once the form is republished, existing forms will contain the proper workflow status in the form.