How To: Add Basic Workflow with InfoPath Roles and Rules

Adding basic workflow to a form template is accomplished without custom code by using two built-in features of InfoPath, namely User Roles and Rules. User roles allow you to categorize users into one or more groups, either based on data in the form template or on Active Directory. Rules allow you to switch views, query a data source, display a dialog box or submit the form based on a condition, such as a user's role, another field's value, or an XPath expression. Only the first condition, that of the user's assigned role, will be demonstrated.

Bb251015.vs_note(en-us,office.12).gif  Note
If you have Windows SharePoint Services 3.0 available, see How To: Add SharePoint Workflow Support to an InfoPath Form.

For the purposes of demonstrating a simple workflow, you will create a form template with the following features:

  • Two user roles, one named "Employee" and one named "Manager."
  • Two views, one named "Expenses" and one named "Manager Approval."
  • Two data connections for submitting the form by e-mail, one called "Standard" and one called "For Approval."
  • A "Total" field in the data source.

Adding User Roles

User roles can be based on an Active Directory structure, such as a username or a groupname that exists in a domain, or on data returned from a data connection. To display the Manage User Roles dialog box, click User Roles on the Tools menu. Then click the Add button to display the Add User Role dialog box, as shown in Figure 1, to add a role based on a username or groupname in a domain, or on data returned from a data connection. You can also select the Set as initiator check box to designate a role as the default one used when a new form is created based on the form template.

Figure 1: Add User Role

For more information about adding user roles, search the InfoPath Help for adding a user role.

Adding a View

For the purposes of demonstrating how to switch views, rename the default view and add a second view to the form template:

  1. On the Views task pane, click the View Properties button.
  2. Change "View 1" in the View name box to "Expenses."
  3. Click OK.
  4. Click the Add a New View link on the Views task pane.
  5. Name the new view "Manager Approval."
  6. Click OK.

Adding a Rule to Switch Views on Open

Once you have user roles defined and a view added, it is easy to create a rule to switch views based on the current user's role. To switch views when a form is first opened, the rule must run at that time. Follows these steps to create a rule that runs when a form is opened:

  1. Click Form Options from the Tools menu.
  2. Click the Open and Save category in the Form Options dialog box.
  3. Then click the Rules button in the Open behavior section.

In the Rules for Opening Forms dialog box:

  1. Click the Add button.
  2. Give the rule a name.
  3. Click the Set Condition button.

This will display the Condition dialog box, which contains a series of three drop-down list boxes as shown in Figure 2.Figure 2: Setting a Condition for a Rule

Click the first drop-down and select User's current role. The second drop-down, unless changed, has a value of is equal to. Click the third drop-down to select "Manager," then click OK.

Once the condition is set, add an action to switch the view based on the user's role.

  1. Click the Add Action button on the Rule dialog box.
  2. Choose Switch views from the Action drop-down list box.
  3. Choose the "Manager Approval" view from the View drop-down list box.
  4. Press OK four times to dismiss all dialog boxes and return to the form.

Adding Data Connections

Adding two data connections to submit the form by e-mail allows for the form to be submitted through the "Standard" connection if an employee submits the form and the total amount is less than $1000, or if the manager submits the form. If an employee submits the form and the total amount is greater than $1000, the "For Approval" data connection is used to send the form and an e-mail to the manager. To set up these data connections, open the Data Connections dialog box from the Tools menu. In the Data Connection dialog box, click the Add button and use the following steps to create two e-mail submit data connections:

  1. Click Create a new connection to:, then Submit data on the first screen of the Data Connection Wizard. Click Next.
  2. Click As an e-mail messsage for the How do you want to submit your data? option on the second screen. Click Next.
  3. For the To: line, insert a valid email address. When creating the second data connection, use a different email address in order to test the submit rules.
  4. For the Subject: line, insert either "Expense Report" for the "Standard" data connection or "Expense Approval" for the "For Approval" data connection. Click Next.
  5. Select Send the form data as an attachment, and check the Attach the form template to ensure that users can open the form checkbox. Click Next.
  6. Name the connection either "Standard" or "For Approval," depending on which e-mail data connection you are creating, then click Finish.
  7. Repeat steps 1 through 6 to create the second e-mail data connection.

Adding a Total field

  1. Drag a Text Box from the Controls task pane onto the form.
  2. With the text box selected, click Text Box Properties on the Format menu.
  3. In the Text Box Properties dialog box, change the Field name to "Total" and the Data type to Decimal (double), then click OK.

Enabling the Submit Button and Adding Logic

  1. Click Submit Options on the Tools menu.
  2. Check the Allow users to submit this form and click Perform custom action using Rules.
  3. Change the caption of the Show the Submit menu item and the Submit toolbar button to "Submit Expenses" and then click the Rules button.

Adding Rules for Submit Logic

The submit operation requires three rules in order to express the logic for this simple workflow. The first rule will submit using the "Standard" e-mail data connection if the user's current role is "Manager." The second rule will submit using the "Standard" e-mail data connection if the user's current role is "Employee" and the "Total" amount is less than or equal to $1000. The last rule will submit using the "For Approval" e-mail data connection.

To create the Manager Submit rule:  

  1. Click the Add button on the Rules dialog box.
  2. Name the rule "Manager Submit" and press the Set Condition button.
  3. In the Condition dialog box, select User's current role, is equal to, and "Manager" for the three drop-down list boxes.
  4. Click OK.
  5. Click the Add Action button on the Rules dialog box.
  6. Select Submit using a data connection from the Action drop-down box.
  7. Select "Standard" from the Data connection drop-down box.
  8. Click OK.
  9. Click the Stop processing rules when this rule finishes checkbox.
  10. Click OK.

To create the Employee Submit rule:  

  1. Click the Add button on the Rules dialog box.
  2. Name the rule "Employee Submit" and press the Set Condition button.
  3. In the Condition dialog box, select User's current role, is equal to, and "Employee" for the three drop-down list boxes.
  4. Click the And >> button at the end of the third drop-down list box to add a second condition.
  5. Click Select a field or group from the first drop-down list box and choose the "Total" field.
  6. Click is less than or equal to in the second drop-down list box.
  7. Click Type a number in the third drop-down list box and type "1000" without the quotation marks.
  8. Click OK.
  9. Click the Add Action button on the Rules dialog box.
  10. Select Submit using a data connection from the Action drop-down box.
  11. Select "Standard" from the Data connection drop-down box.
  12. Click OK.
  13. Click the Stop processing rules when this rule finishes checkbox.
  14. Click OK.

To create the Approval Submit rule:  

  1. Click the Add Action button on the Rules dialog box.
  2. Name the rule "Approval Submit" and press the Add Action button.
  3. Select Submit using a data connection from the Action drop-down box.
  4. Select "For Approval" from the Data connection drop-down box.
  5. Click OK on the Rule dialog box, OK on the Rules dialog box, and then OK on the Button Properties dialog box.

Figure 3: Rules for Submitting the form

After completing these three rules, the Rules dialog will look similar to Figure 3.

Previewing by Role

To test the form logic, you need to preview the form using different roles. Click Form Options from the Tools menu and click the Preview category. Select either "Employee" or "Manager" from the Preview as drop-down list box, then click OK. These options are also accessible from the Preview split-button on the Standard toolbar. Click Preview on the Standard toolbar to test the form logic.

After selecting "Employee" from the Preview as drop-down, preview the form and enter a value of "1500" in the "Total" field and click Submit Expenses. This will display the e-mail submit dialog, which will send an e-mail to the address entered in the "For Approval" data connection.

Bb251015.vs_note(en-us,office.12).gif  Note
If more than one e-mail is sent when the form is submitted, ensure that the first two rules for submitting have Stop processing rules when this rule finishes checked.