Site icon @WonderLaura

InfoPath User Roles in Browser Forms (Part 1 of 2)

This blog post applies to the Enterprise version of SharePoint, not WSS or Foundation.

There’s a concept in InfoPath called “User Roles”.  You can set up these roles, and when a person opens theimage form, the form knows if they belong to a certain role, and you can set up certain objects to hide or show in the form based on the user’s role, or switch to a view based on a role, etc.  Each role that you set up can be defined by specific user names, Active Directory groups, or a person’s name from within the form, like this:

UNFORTUNATELY, there are a couple of limitations of this functionality in InfoPath.

  • User roles are NOT available when creating browser-based forms.  Therefore, if your form absolutely requires these, then all users who ever fill out this form will need to have the InfoPath software installed on their computers.  This is a huge limitation in a lot of cases.
  • User roles cannot be created based on SharePoint Groups, only AD groups.

There’s a blog post out there, that describes a a way to get around this limitation, and emulate user roles in a browser based form.  BUT this method entails manually keeping up a separate SharePoint list where you define all of the users and their roles.

Today, I’m going to tell you about another way of using the currently logged in user’s information instead of roles, and this can be used in a browser-based form.  This can be used with SharePoint groups, where the built in user roles cannot.  The trick is a built in SharePoint web service called the user profile service.  Lori Gowin blogged a while back about how to use this web service in order to auto-populate text boxes in any SharePoint form, with information about the current logged in user.  My method entails using that same web service.  Clarification: This doesn’t refer to ANY SharePoint group, this is only the “members” group that exists on each SharePoint site.  There is another web service that can be used, UserGroup.asmx, in order to get the info about SharePoint groups in general, on a site.

There are a couple of very useful operations in the UserProfileService.asmx web service, so I’ll show you a couple of options (2 parts to this blog).  In this example, you have a change request form.  Site visitors fill out the form, and after they’ve filled it out, people in the IT department will have additional fields to fill in.  We don’t want non-IT staff to see these additional fields, though.  We will create another view in the form.  This view will contain all of the original fields that were filled in by the originator, plus the additional IT fields.  When the form is opened, we want it to automatically switch to this IT view when the logged in user is an IT person.  The prerequisite is that there is a SharePoint group on your site called IT Group, and you are a member of it.  Also, you’ll need a form with 2 views, one of them called IT Dept.

  1. Create a new data connection in the InfoPath form, to receive data.  The source is a web service.  (In SharePoint 2010, pick SOAP web service.)  Click NEXT.
  2. Type the URL of the userprofileservice.asmx file.  This is at the root of your SharePoint site, under the _vti_bin folder.  Click Next.
  3. For the operation, click GetUserMemberships, and click NEXT.
  4. On the Parameter screen, just leave the default and click NEXT.
  5. Leave “store a copy of the data…” unchecked, and click NEXT.
  6. Leave “Automatically retrieve data when form is opened CHECKED, and click FINISH.
  7. Now, when someone opens my form, I want the form to automatically switch to the IT view if the user is in a SharePoint group called “IT Group”.
    • In InfoPath 2010, click the Data tab in the ribbon, and click the Form Load button, which will bring up the Rules pane on the right.
    • In InfoPath 2007, click the Tools menu and choose Form Options.  Click the Rules button on the Open and Save section.
  8. Define the rule as so:
    The condition is: Click the first drop-down box (the field name).  Click “Select Field or Group”.  In the drop-down for the data source, select GetUserMemberships, which was the first data connection that you created.  Expand several levels and select the DisplayName field.  Click OK.
  9. For the value, click “type text” and type IT Group, as so.  Click OK.
  10. Click to add the Action.  The action will be just to switch views.
  11. The action is just to switch views, so you’re done with the form open rules now.
  12. Now try it out.  Publish the form.  If you’re a member of the IT Group (SharePoint group), the form will now automatically switch to the IT Dept view when it opens.

Stay tuned for part 2 of this blog post, for another way to go about accomplishing something similar with this same web service.

Testing:  This GetUserMemberships operation returns a list of all groups that the current user is a member of, SharePoint and Active Directory.  In order to see exactly what is returned from this operation, here’s how you can do this.  In the data source pane on the right side of InfoPath, click the Main drop-down box at the top of it and change the data source to GetUserMemberships.  This will show all the fields.  Expand several levels until you get to the one called MembershipData.  Drag this whole group of fields onto your form, as a repeating table.  Preview your form.  This will show you a list of all the groups that you are a member of.  You may need to increase the width of the Display name field, so that you can see all the values.  You’ll also notice that there is a field called Source that shows whether each one is a SharePoint group (“SharePointSite”) or a Distribution list.

Exit mobile version