Restrict InfoPath Section Visibility Based on User

Introduction

During a recent client build (JPMC), I had a custom SharePoint list InfoPath requirement where I had to restrict a section of the InfoPath form view (I created 4 in total…see more here) to a specific group of users (‘Management Use’ only).  Instead of simply marking the section/fields with a heading such as ‘Management Use only’, I can show or hide this section based on the logged in user and separate custom permissions list where we can maintain the specific management group.  This ariticle describes how to achieve that in InfoPath.


Table of Contents

 

 


Creating the ‘Management’ List

In order to restrict sections in the form, create a custom list that contains the users who will have access to the section.  We will reference this list in a data connection in InfoPath.

  1. Create a custom list and name it: ElevatePermissionsUsers
  2. Create a new column:
    1. Column name: Admin/User
    2. Type: Person or Group
    3. Required: Yes
    4. Allow selection of: People Only
    5. Accept the defaults for everything else
  3. In Advanced Settings, Allow management of content types
  4. Change the Item content type and hide the Title field
  5. Change the default All Items view:
    1. Remove the Title field
    2. Add Edit (link to edit item) and move it to the first column

Now your list is ready, Add a couple of site users to the list.


Customizing the InfoPath List Form

If you don’t already have a list form that you need to customize, create one now. It can be based on a Custom list template, or any other list template that you need, such as Tasks.

Add linkage fields

For this customer, I created a custom list and named it IOLRequest.  By adding two additional fields, IsAdmin (number, hide in all views) and CurrentUser (single line of text, hide in all views) to IOLRequest, I created a relational interchange between IOLRequest and the previously created ElevatePermissionsUsers.

Now let’s return to the InfoPath List Form by clicking the Customize in InfoPath button from any IOLRequest list view.  Click on the DATA tab on the InfoPath Ribbon, then go to Manage Data Connections.

GET_ElevatePermissionsUsers screen grab

GET_ElevatePermissionsUsers screen grab

Manage Data Connections

Add a New connection to ElevatePermissionsUsers list and name it GET-ElevatePermissionsUsers.
Select the following fields:  
AdminUser
ID

Accept the defaults and complete the wizard steps

 

 

Create the Rules
  1. Select the DATA tab in the ribbon
  2. In the Rules section, click on the Form Load button
  3. Create a new Action rule and name it Assign Admin Users
  4. Accept the default Condition – None – Rule runs when form is opened
GET-ElevatedPermissionsUsers-ChangeData

GET-ElevatedPermissionsUsers ChangeData

6.Create a new Set a field’s value action:

  • Field: IsAdmin
  • For Value, click on the fx button
  • Click Insert a Field or Group
  • Click on Show advanced view
  • Change the data source to GET-ElevatedPermissionsUsers
  • Under dataFields, drill down and select ID
7. Click Filter Data
8. Click Add
9. In the first drop-down box change ID and click Select a field or group…
10. On the Data source dialog, under dataFields, drill down and select AdminUser AccountID
11. Click OK
12. Accept the default in the second drop-down: is equal to
13. From the third drop-down, select Use a formula…
14. On the Insert Formula dialog, click the middle button Insert Function…
15. Select the userName function and click OK
16. Click OK several times to close all dialog boxes

The final Rule Details dialog should look similar to the image at right:

Manage Restricted Section

1. Click on the section tab that contains your restricted content
2. Create a new formatting rule and name it Hide From Non-Admin Users
3. Set the condition to IsAdmin = Is blank
4. Select the Hide this control check-box
5. Right-click on the CurrentUser field in the fields section and select Field Properties…
6. Change the Default Value by clicking the fx button next to the Value text box
7. Insert the userName function

Publish the form

Test the form by signing in to the site with a user who is in the ElevatedPermissionsUsers list, then with one who’s not in this list.

Leave a Reply

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