User Roles and InfoPath Forms Services
For InfoPath 2007 forms designed to work both in the InfoPath Client and in the web version using InfoPath Forms Services, many features are not available if the form had been designed to work in just the InfoPath Client. One of these features is the User Role. A workaround can be implemented to get this functionality to be available for the client and web versions of the form. Since the InfoPath form can be viewed using the browser, the InfoPath Form Template will be hosted in a SharePoint Form Library.
In the InfoPath 2007 Design mode, a data element needs to be created for each User Role. The data element for each User Role is of data type “Text (string)”. The following are the steps to create one or more User Roles.
From the “View” menu item, select “Data Source. The “Data Source” task pane will appear on the right side of the design view.
Create a new data element of data type “Group” which will hold the data elements or User Roles.
Create a new data element of data type “Text (string)” for each User Role required.
The next step is to assign users to the recently created data elements. There are two ways to go about this next step. The first method is to assign users directly into a User Role in InfoPath by using the User Role’s data element default value setting. The second method is to use a SharePoint list to assign the users to their respective User Roles.
This is the easiest method to assign users into each User Role. The drawback to using this method is that the form template will need to be edited and re-published on any instance of a change to a user in a User Role. The following are the steps to add users directly into a User Role inside InfoPath.
Navigate to the Data Source task pane and select a User Role.
Open the properties of a User Role by double-clicking on the User Role.
In the Default Value section of the window, enter the Window Domain ID’s of the users in the “Value” textbox. The ID’s of the users are separated with commas.
Assign Users with SharePoint
This method has many steps and is, therefore, more difficult to set up then the method using just InfoPath. The benefit of using this method is that user information can be updated on SharePoint, therefore, the editing and re-publishing of the InfoPath template is not required when there is a change in a User Role. The following steps are used to setup the User Role information using SharePoint.
Navigate to the site where the Forms Library that contains the form template resides.
Click on “View All Site Content” at the top left of the site.
Select the “Create” link located below the Title of the page.
In the new page that appears, select the “Custom List” option. This list will contain the User Role information and the Windows Domain ID information of the users.
In the next page that appears, enter a name for the new list. Add a Description for the list and select “Yes” or “No” if a link to this list should appear on the top left navigation area. Then select the “Create” button.
After the list is displayed, select the “Settings” option in the toolbar and then select the “List Settings” option in the drop-down that appears.
In the Customize page, select the link called “Title” in the Columns section.
In the page that appears, change text in the “Column name:” field from “Title” to “Group” or similar text. Then select the “OK” button.
In the Customize page, select the “Create column” option in the Columns section.
In the page that appears, enter “Usernames” or similar text into the “Column name:” text field. Below the line that reads “The type of information in this column is:” select the radio button for “Multiple lines of text”. Under the line that reads “Number of lines for editing:” enter the number “1” in the text field. Under the line that reads “Specify the type of text to allow:” select “Plain text”. Ensure that “Append Changes to Existing Text” is set to “No” and that the check box before “Add to default view” is checked. Then select the “OK” button.
The Customize page will once again appear, navigate back to the list using the breadcrumb trail.
In the toolbar, select the “New” option.
In the New Item page that appears, enter the User Role name in the “Group” field. This name should be similar to the data element name in InfoPath. In the “Usernames” field, enter the Windows Domain User ID information of the users that belong in this User Role. Separate multiple users with commas. Select the “OK” button when completed.
Repeat the previous step for all the User Role data elements created in the InfoPath form. After completion, navigate back to the InfoPath form.
From the “Tools” menu item, select “Data Connections”.
Select the “Add” button to create a new data connection to the newly created SharePoint list.
In the Data Connection Wizard, select the “Receive data” option in the “Create a new connection to” section. Select the “Next >” button.
Select the “SharePoint library or list” option and the select the “Next >” button.
Enter the URL of the SharePoint List and the select the “Next >” button.
Select the newly created SharePoint List from the section “Select a list or library” then select the “Next >” button.
In the “Select fields:” section, check the checkboxes for “Group” and “Usernames”. Then select the “Next >” button. Select the “Next >” button on the following screen.
Enter a proper name for the data connection in the text field below the “Enter a name for this data connection:” text.  Ensure that the “Automatically retrieve data when form is opened” is checked. Then select the “Finish” button.
In the “Data Connections” window, select the “Close” button.
From the “Tools” menu item, select “Form Options”.
In the “Form Options” window, navigate to the “Open and Save” section and select the “Rules” button. A rule will need to be created for each User Role that was created.
Select the “Add” button. Provide a name for the Rule, preferably a name similar to the User Role that this Rule will apply to. Select the “Add Action” button.
In the “Action” window, select the “Action:” to be “Set a field’s value”.
Set the “Field” to a User Role data element.
For the “Value:” field, select the “fx” button.
In the “Insert Formula” window that appears, select the “Insert Field or Group” button.
In the window that appears, select the name of the newly created data connection in the “Data source:” drop-down. Drill down to and highlight the “:Usernames” option or the name that was defined for this SharePoint column. Then select the “Filter Data” button.
In the new window, select the “Add” button.
The “Specify Filter Conditions” that appears will have three drop-downs.
For the first one, select the item called “Group” or the name that was defined for this SharePoint column.
The second drop-down will have the value of “is equal to”.
The third drop-down will require the selection of the “Type text…” option to enter text. The text to be entered is the value of the “Group” SharePoint column the current Rule is being created for. For example, if a rule is being created for the User Role “Development” and the name of the “Group” item in the SharePoint list is “Dev”, then the third drop-down value needs to read “Dev”.
Select the “OK” buttons to return to the “Rules for Opening Forms” window.
After creating a rule for all the User Roles, select the “OK” button. Then select the “OK” button the on the “Form Options” window to complete the method.
After the User Roles have been set, the roles will then need to be applied to the controls. The following steps are an example of the User Roles being applied, regardless of the method used to assign user’s to the User Role data elements.
To create Conditional Formatting on a control, open the Conditional Formatting window and select “Add”.
Then on the first drop-down in the “If this condition is true:” section, select the name of the User Role data element.
The second drop-down will read “does not contain” or “contains”, depending on the formatting required.
The third drop-down will require the option “Use a formula” to be selected. In the “Insert Formula” window, select the “Insert Function” button. The function that will need to be selected is called “username”. Select the “OK” buttons to return to the Conditional Format window.
Apply one for more formatting options below the “Then apply this formatting:” line of text. Then select the “OK” button.
This workaround will not only work for web-based forms (using InfoPath Forms Services), but also for the InfoPath Client forms. This workaround will also work for InfoPath forms that have been saved onto a computer and need to be accessed offline.