Infopath form that switches views based on the current user

List based forms are considered browser based forms. Browser
based forms can use the InfoPath Username() function to capture the current
user account id. The limitation is that you can’t grab user profile properties
with this method.

Occasionally, you may have a requirement to switch views on
a form based on the current user. You can do this with the following item:

  • Data connection in the list form
  • A separate list that stores the account ids of persons who should
    see the view

Create a list with a people column that has Account ID on
it. When creating a list item, you can enter a name and the account id will
automatically appear. For example, if you need a view on the your form for
Subject Matter Experts, you can create a Subject Matter Expert list. In that
list, you would add a column, for this example called UserId, with the
following settings:

In Show Field, make sure you select Account. This allows you
to make a comparison with the information about the current user captured on
the InfoPath list with the personnel in this list.

Browse to the list where you want to use your form.

<>In the list for InfoPath form, create a text column called UserName and another text column called
SubjectMatterExpert.

Create an InfoPath list form by clicking Customize Form on
the List tab on the list ribbon.

Create a second view in the InfoPath form called Subject
Matter Expert View. Do not make this view the default view.

In the InfoPath form, create a data connection to the
Subject Matter Expert list.

Make sure you select the UserId column in the data
connection.

Make sure to check the box to get data on load called Automatically
retrieve data when form is opened
.

On InfoPath form, select the UserName column. Right-click
and select Text Box Properties.

Set the default value of the column to the function
UserName().Make sure you select the checkbox for Refresh Value when Formula
is Recalculated
.

On InfoPath form, select the Subject Matter Expert column
and bind the column to the Subject Matter Expert data connection. Right-click
and select Text Box Properties.

Click the fX button.

Click Insert Field or Group.

Click Advanced View.

Select the SubjectMatterExperts data connection.

In the dataFields section of the tree, select the AccountId.

Click Filter Data.

Oon the Specify Filter Conditions dialog box, click Select a
field for group in the first dropdown and select the AccountId field

In the next box, select is equal to.

In the third box, select Use a formula and select the
userName() function. The dialog box should look like the following picture.

Click OK until the Insert Formula dialog box appears. That
dialog box should look like the following picture:

Click OK to display the Text Box Properties dialog box. That
dialog box should appear like the following picture:

Make sure you select the checkbox for Refresh Value when
Formula is Recalculated
.

You can consider hiding the the Subject Matter Expert column
on the form if you do not want the users to see it.

On the Data tab, click Form Load.

Set up a rule that looks like the following:

Enter a person in the Subject Matter Expert list. Test the
form by asking that person to open the form. The Subject Matter Expert view
should appear automatically.

Browser-based Infopath forms and the User Profile Service

Browser based InfoPath forms present the 5566 error when
trying to access the UserProfile service in a claims based environment. This
error can be resolved by creating a UDC file and selecting Allow
user form templates to use authentication information contained in data
connection files
in Central Admin in the InfoPath
Forms Services area. The steps are outlined in detail in the following article:

https://spvee.wordpress.com/2013/04/10/auto-populate-user-information-in-infopath-with-claims-based-authentication-part-1-of-3/

Leave a Reply