Site icon @WonderLaura

InfoPath: Pre-populate the People Picker


In business forms, a common requirement is to pre-populate a people picker control, such as to default to the name of the currently logged in user, which would then allow them to pick someone else if needed.  For example, a secretary could fill out a travel request for her boss, and in the “Traveler” people picker, she could pick his name instead of her own.

This solution can be done with any version of SharePoint 2010 or SharePoint Online with Office 365.

If you have Foundation, use my method in this other post in order to get the current user information, instead of the user profile service data connection:

If you are on SharePoint 2013 or Office 365, there is an extra step: Upgrading InfoPath and the User Profile Service Data Connection by Lori Gowin.  You do this after step 5 below…

7/8/2015 Update:  I’m doing a whole SharePoint Power Hour on this topic, so tune in live, or watch it later here:

Here’s a little bit of background on how the people picker is structured:

It is structured as a repeating table, and the “group” can be renamed.  No other fields can be renamed

DisplayName = Laura Rogers
This is the first name and last name of the user, which is going to be equivalent to the value of the PreferredName field in the user profile service.

AccountId = contosolaura
This is domainusername

AccountType = User
This is User or Group.

Here are the steps to prepopulate the people picker:

  1. On the Data tab, click Data Connections.  Click Add..
  2. Choose Receive data and click Next.  Choose SOAP web service, and click Next.
  3. Type the URL of your site, and after the site, type /_vti_bin/userprofileservice.asmx
    Click Next.
  4. Choose GetUserProfileByName.  Click Next.  Click Next.  Click Next. Click Finish.
  5. All we’ve done so far is create a connection to the user profile service web service, so that we can get some additional information about the logged in user.  Since we only want the people picker to get pre-populated when it’s a new form, we’re going to create a form load rule that does this.
    If you haven’t already placed a people picker control on your InfoPath 2010 form, go ahead and do that.
  6. On the Data tab, click Form Load.
  7. In the form load rule pane on the right, click New and choose Action.
  8. We only want this to happen if there’s no name in the people picker yet, so we’ll create a condition first.  Under the word “Condition”, click the blue word None – …
  9. Creating the condition: In the first drop-down box (myFields), click Select a Field or Group.  Navigate down to your people picker control group and expand it.  Select the AccountId and click OK.
  10. On the condition’s second drop-down, choose Is Blank.  Click OK.
  11. Back in the form load rule pane, click Add and choose Set a Field’s Value.
  12. For the Field box, select the DisplayName field inside your people picker form (that DisplayName field you see in the screenshot at step 9).  Click OK.
  13. Click the fx (function) button next to the Value box.  Click Insert Field or Group… In the Fields drop-down box, choose GetUserProfileByName.

  14. Drill all the way in the DataFields until you get to Value.
  15. Click the Filter Data button.  Click the Add button.
  16. In the first drop-down box that says Value, choose Select a field or group.  Select the Name field.  Click OK.
  17. Leave the middle drop-down to say Is equal to.  In the third drop-down box, choose Type text.  Type the word PreferredName
    It will automatically put the quotes around it for you, you don’t need to type those.  (this is case sensitive, so you have to type it exactly right) Click OK.
  18. On the Filter Data screen, click OK.  On the select a field or group screen, click OK.  On the insert formula screen, click OK.
  19. This is what your Rule Detail screen will look like.  Click OK.
  20. Back over in the form load rule pane on the right, click the Add button again, and choose Set a field’s value.
  21. For the Field, drill down to your form’s people picker, and select the AccountId field, as seen in step 9.  Click OK.
  22. Repeat steps 13-16.
  23. Leave the middle drop-down to say Is equal to. In the third drop-down box, choose Type text. Type the word AccountName
    Click OK.
  24. This is what your Rule Detail screen will look like.  Click OK.
  25. In the Rule pane on the right, click the Add button yet again.  Choose set a field’s value.
  26. For the Field, pick the AccountType field within your people picker.  You can see what this field looks like back in step 9.  Click OK.
  27. In the Value box, just type the word User
  28. This is what your Rule Details screen will look like.  Click OK.
  29. Done.  Publish your form and try it out.  When you fill out a new form, your own name will be populated in the people picker.

If you need to do this solution in SharePoint 2007, follow Lori Gowin’s 2 part blog series that starts here.

Exit mobile version