July 31, 2010
Developer In-Depth:
prev
next
- Podcast
- Research
- Search
- Security
- Technology
- Video
- AIM
- Alfresco
- Collaboration
- ECM
- ESX
- Hyper-V
- IE8
- Internet Explorer
- Iomega
- Linux
- MIX08
- Microsoft
- NAS
- Nokia
- REV
- S60
- SaaS
- Sharepoint
- Silverlight
- Sony Ericsson
- VMware
- Windows Live
- YouTube
- Advertising
- Backup
- Beta Test
- Blogs
- Convergence
- Display
- Enterprise
- Humans
- Instant Messaging
- Multimedia
- Networking
- Open Source
- Phishing
Implement Roles-Based Logic in InfoPath Forms
When we create business solutions that leverage Microsoft InfoPath Forms Services (a MOSS Enterprise edition feature), we often see the need to hide or disable sections, buttons, fields or entire views based on the logical role of the user. For instance, wed may want to show an admin button that allows a user to switch to an admin view showing useful state or audit information about the InfoPath form that shouldnt normally be visible to ordinary end users.Its easy enough to determine the ID of the current user who is viewing the form via the username() function and in some limited cases, we could try to leverage that to meet this kind of requirements. However, there are two major problems with this approach:
Admittedly, its fairly rare to use InfoPath in an FBA environment, but if you need to identify the current users role, you cant use the username() function. The technique described by this tip solves that problem.
- 1. Wed have to hard code user names in our logic with all the attendant issues that go with that.
- 2. The username() function doesnt work well in an forms based authentication environment (FBA).
The Solution
This solution leverages SharePoints item level security model. The idea goes like this:
Lets quickly walk through this scenario. Well perform the following tasks:
- Create a custom list. Dont add any custom columns - the standard Title column is sufficient.
- Add one entry to this custom list for each role. For example, add Admin and Approver roles.
- Define security access at the item level for each of these roles.
- Add a data source to your custom list pointing to the custom list.
- At run-time, your InfoPath form attempts to read the specific row in the list based on the rows title. If the run-time user has read access to the item, they belong to that role. Otherwise, they do not.
In order to follow along with this tip, you will need two separate user IDs (to test out different roles), a sandbox environment where you can create a custom list and the ability to publish an InfoPath form.
- Create a custom list, add a few role-type entries and define appropriate item-level security.
- Create an InfoPath form with the following:
- Data source linked to the custom list.
- A few Boolean fields to mark whether the current user is a member of a role.
- A rule that fires when the form is opened that determines whether the current user has access to the role-specific row in the custom list.
Create a custom list
Create a custom list in your favorite sandbox environment. Add two rows where:
When complete, your list should look similar to the following:
- Row 1 title = Admin
- Row 2 title = Approver
Access the Admin item and break its inheritance to allow only your favorite admin account read access. First, access the lists permissions as shown:
From there, break inheritance as shown:
Networking Solutions
Most Popular Stories
- 1 Building SharePoint Suggestion Boxes and Soliciting Anonymous Feedback
- 2 Moving a Document to the SharePoint 2010 Records Center
- 3 Solve Item-Level Permission Performance Problems in SharePoint
- 4 Developing SharePoint Solutions in Visual Studio Using WSPBuilder
- 5 Using the Event Handler in SharePoint 2010
- 6 Prepare Your SharePoint Data Carefully, Ediscovery Experts Warn
- 7 Design a Form to Collect Customer Information Using InfoPath and SharePoint 2010

Extending database skills is fast and easy with new features and this e-kit. Learn how and start taking advantage of easier DB2 administration features today.