Alternative for using Roles in InfoPath Browser based forms

Roles in InfoPath are a great way for breaking your form up and identifying users for handling certains tasks/sections of the form. However a common problem for people are that InfoPath User Roles can be cumbersome, as you need to republish the form each time you want to add users to it and they are not compatible with Browser Enabled forms.

A simple workaround to this is through the use of SharePoint Lists and SharePoint profile webservices. The object is to use the SharePoint “GetUserProfileByName” webservice to determine who is currently browsing the form, then based on a criteria that checks that user against a SharePoint list of users that will decide which sections of the form they are able to see.
I’ve given out the steps in a simple example below

To get started first you’ll need to figure out what are the roles for your form. For my example I will be using 2 unique roles -Administrator and Business Analyst- and 1 default role that is open to all users.

For each of my unique roles I will need to create a custom list in SharePoint that utilizes the title column to store the usernames of people that belong to this role. I will then populate the lists with a couple of usernames in the format of “domain\username” all lower case (this important). See my example for the administrators role:

Another list was created for the Business Analyst role as well:

Now that i have my role lists set up the next step will be to create the form.

  1. Start with a blank form and add 3 sections to the form. Name them based on the roles.
  2. Next populate the sections with what ever controls you want to be available to that role.
  3. Next we will set up our Data Connections for the Administrator list by going to Data tab> Data Connections and clicking Add
  4. select Create a new connection to Recieve data, click next
  5. select “SharePoint library or list”, click next
  6. Enter the location of your site that hosts the lists and click next
  7. select your Administrators list, click next
  8. check off the title field selection box, click next, next
  9. Enter the Name you want for the data connection, list name is default, then click finish.
  10. Repeat steps 3-9 for the Business Analyst role and any other roles you have
  11. Next you need to add the data connection for the GetUserProfileByName webservice (http://<Your Site>/_vti_bin/UserProfileService.asmx), see my last post on how to do this https://brenthafnersblog.wordpress.com/2012/05/09/auto-populate-infopath-people-pickers/

    Next we need figure out who is logged into the form
  12. Add a textbox to the administrators section called currently logged on
  13. Set the value of the currently logged on user by using a form load rule
    1.  Go to Data Tab > Form Load > New Action
    2.  The condition should be left to None
    3.  Click Add beside the Run these actions, and choose set a fields value
    4.  For the field select your “CurrentUser” text box from the administrators section and for the value use the formula link ƒx
    5.  click insert function and select translate from the text category.
    6.  double click the first field of the translate function and select from the drop down your “GetUserProfileByName (Secondary)” data connection, and expand the dataFields node all the way down to Value.
    7. Select Value and click Filter Data, then click add.
    8. For the first value of the filter condition choose select field or group, and select “Name” from the PropertyData category of your “GetUserProfileByName” data source.
    9. set the condition to is equal.
    10. for the third field insert the following text “AccountName”
    11. click ok, ok to get back to your original translate function for the next 2 fields insert the following “ABCDEFGHIJKLMNOPQRSTUVWXYZ”, “abcdefghijklmnopqrstuvwxyz”. (This will ensure usernames come out in all lowercase)
    12. your formula should resemble the following:

    13.  click ok, ok to finish with your form load rule.
  14. Now that we know who is currently logged on the last thing will be to compare that user to our list of admins and business analysts to determine if they are allowed to see the corresponding sections.
  15. Start by selecting the business analyst section and clicking New Formating in the “manage rules” panel. Then click “None” under the Condition.
  16. For the first field choose “select a field or group”, then choose your BusinessAnalysts data source (SharePoint List).
  17. Expand the dataFields node all the way down and highlight Title.
  18. Under the select drop down choose all occurrences of Title
  19. click ok and choos “are not equal to” for the operator field
  20. for the second field select your CurrentUser field from the administrator section
    Your condition should look like the following:
  21. The last step for this formating rule is to select Hide Control check box since we only want Business Analysts to see the form.

Finally once you repeat steps 15-21 for the Administrators role you should be good to go.

Going forward whenever you need add users to a role you merely need to add the user to the corresponding SharePoint list. See what a user would see if they have been added to the Business Analyst list.

We have now just completed a browser ready form with a workaround to setting up User Roles.

Advertisements