Switch View View Based on User ID In An InfoPath Form

We had a developed an InfoPath form with multiple views to support a new hire / on-boarding process.  When the company hires a new person, the IT department and other groups need to take action (set up payroll, enable access to appropriate applications, locate a desk, etc).  We use on form but a different view of the form for each of those functions.

At this company, most of the people involved in the business process are IT-savvy, so when they access the form, their default view is a "menu" view with buttons that direct them to their specific function.  However, we needed to simplify things for the new hire’s direct manager.  This person should not see any of the IT related stuff.  In fact, she should see just one view of the form and not even have an option to see the other views.

In our case, that direct manager’s account is directly tied to the form courtesy of a contact selector (which I am always wanting to call a "people picker" for some reason).

The steps are as follows:

1. In design mode, go to Tools -> Form Options -> Open and Save.

2. Select "rules".

3. Create a new rule whose action is "switch to view" and whose condition leverages the userName() function.

userName() returns the "simple" user name without the domain.  If I log into SharePoint with credentials "domain\pagalvin", userName() returns "pagalvin".

The contact selector provides three bits of information for a contact.  The "AccountID" portion is most useful for this scenario.  The only thing that makes this even a little bit of challenge is that the contact selector (in my environment anyway) returns the domain and user ID, as in "domain\pagalvin".  This prevents us from doing a straight-forward equality condition since AccountID ("domain\pagalvin") will never equal userName() ("pagalvin"). 

We can get around this using the "contains" operator: AccountID contains userName().

We can take it further and pre-pend a hard-coded domain in front of the userName() function to get our equality check and eliminate the risk of a false positive on the contains operator.

We would have REALLY like to automatically switch view for other users based on their AD security group membership.  For example, when a member of the "IT Analytics" group accesses the form, automatically switch to the IT Analytics view.  We didn’t have time to implement it, but my first thought is to create a web service that would have a method like "IsMemberOfActiveDirectorySecurityGroup", pass it the userName() and return back true or false.  Does anyone have any other, more clever idea?  Is there any SharePoint function we can leverage from InfoPath to make that determination?

</end>

Technorati Tags:

3 thoughts on “Switch View View Based on User ID In An InfoPath Form

  1. Pingback: Infopath Switch View Based On User « Sladescross's Blog

Leave a Reply

Your email address will not be published. Required fields are marked *