Show/Hide Controls In InfoPath Form For SharePoint Lists - Part One

InfoPath is still one of the most widely used form choices for SharePoint. In this article we will see how to make a section visible to certain users for a SharePoint list form designed in InfoPath. This blog is divided into two parts for better understanding and readability.
 

Assumptions/Prerequisites

  • The users’ permission levels will be maintained in a SharePoint list instead of a SharePoint group. The platforms in consideration are SharePoint 2016 and InfoPath 2013
  • We will also assume that the InfoPath form is created and published. It has got two sections which are visible to everyone (there is no permission-based visibility implemented at this point time)
This is how the form looks to begin with.
 
Show/Hide Controls In InfoPath Form For SharePoint Lists 
After following the steps outlined below, only the section title “For HR use only” will be visible to the HR users and the section titled “For Leadership use only” will be visible to Leadership.
 
There are two lists we will deal with,
  • Employees (this is the main list)
  • Permission Configuration (this list holds the permission levels of users) 
Step 1 - Creating the Permission List
 
In this step, we will configure the permissions list. Create the following fields in permission list.
  • Grant Access to (this is a People and Group field)
  • Permission Level (this is a choice field with two options – HR and Leadership)
If you wish, you can remove the default “Title” field from the content type. To do that follow this path,
 
List settings - Advanced settings - Allow management of content types (Yes) - Ok - Content types - Item - Title - Column settings (Hidden) - Ok
 
Step 2 - Adding the data connection to Permission List
 
In this step we will create the data connection to the permission list from the Employees list. Open the “Employees” list in InfoPath and from the “Data” tab, click on “Data connections”. Then click on “Add”
 
Show/Hide Controls In InfoPath Form For SharePoint Lists
 
In the next screen that pops up, select “Create a new connection” and then “Receive Data”. Click on “Next”
 
Show/Hide Controls In InfoPath Form For SharePoint Lists
 
Select “SharePoint list or library” and then click on “Next”
 
Show/Hide Controls In InfoPath Form For SharePoint Lists
 
In the next screen, give the URL of the web for your site where the permissions list is hosted (for example: http://black.starkindustries.com/sites/labs). Click on “Next”
 
Show/Hide Controls In InfoPath Form For SharePoint Lists
 
Select the list “Permission Configuration” from the dropdown and then click on “Next”. In this screen check the options “ID” (this will be auto selected), “Grant Access to” and “Permission Level”. Then click on “Next”.
 
Show/Hide Controls In InfoPath Form For SharePoint Lists
 
Click “Next” on the following screen and “Finish” on the subsequent screen to finish this step. The data connection is now ready for use.
 
Step 3 - Create the flags in Employees List
 
Create two additional fields in “Employees” list.
  •  isCurrentUserHR (single line of text)
  •  isCurrentUserLeader (single line of text) 
 Show/Hide Controls In InfoPath Form For SharePoint Lists 
 
We will need those two fields above in the next step.
 
Step 4 - Create a flag for HR user​
 
In this step, we will create a rule to identify if the logged in user is an HR. From the “Data” tab, click on “Form Load” and click on a new “Actions”.
 
Show/Hide Controls In InfoPath Form For SharePoint Lists
 
Name the rule something meaningful for instance – “Confirm HR user”. Set the condition as it is i.e. Rule runs when form is loaded. Next, add an action next – “Set a field’s value”. In the next screen, click on the button next to “Field”, and select the “isCurrentUserHR” field and click on “Ok”.
 
Show/Hide Controls In InfoPath Form For SharePoint Lists
 
In the "Value" section, click on the function (fx) icon and click on “Insert Field or Group”, then click on “Show Advanced View” 
 
Show/Hide Controls In InfoPath Form For SharePoint Lists
 
Change the data connection to Permission Configuration (Secondary) from the selection. Select “ID” from the dataFields as shown in the screenshot below.
 
Show/Hide Controls In InfoPath Form For SharePoint Lists
 
Now, we will add two filter conditions. Let’s set the first filter condition by clicking on “Filter data” and,
  • In the first dropdown, select a field or group. Then, expand the queryLists selection till you get “Grant Access to”
Show/Hide Controls In InfoPath Form For SharePoint Lists
  • In the second dropdown, let it remain as “is equal to”
  • In the third dropdown, select use a formula. Click on “Insert Function” and type or select the formula “userName()” 
After adding the above condition, the filter condition should look something like this,
 
Show/Hide Controls In InfoPath Form For SharePoint Lists
 
Now let’s add the second condition, by adding one more row from the “Add” operator, and,
  • In the first dropdown, select “Permission Level”
  • In the second dropdown, let it remain as “is equal to”
  • In the third dropdown, select “Type a text” and enter the text “HR”
Show/Hide Controls In InfoPath Form For SharePoint Lists
 
Click “Ok” multiple times till all the pop-ups close.
 
Show/Hide Controls In InfoPath Form For SharePoint Lists
 
This marks the end of this step, as well as the end of this article. Stay tuned for the final part of this article!