Skip Ribbon Commands
Skip to main content

Laura Rogers @WonderLaura

:

Quick Launch

Laura Rogers @WonderLaura > Posts > InfoPath 2010: Pre-populate the People Picker
Hi everyone,
My blog now has a new URL!
You can now find me at http://www.wonderlaura.com
June 27
InfoPath 2010: 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. 

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

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 = contoso\laura
This is domain\username

AccountType = User
This is User or Group.

image

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.
    image
  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.
    CropperCapture[38]
  10. On the condition’s second drop-down, choose Is Blank.  Click OK.
    CropperCapture[40]
  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.
    CropperCapture[41]
  14. Drill all the way in the DataFields until you get to Value.
    CropperCapture[42]
  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.
    CropperCapture[43]
  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.
    CropperCapture[44]
  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.
    CropperCapture[45]
  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.
    CropperCapture[46]
  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.

 

Comments

GeorgeW

Wonderful!! Thanks Laura !
 on 6/29/2012 9:32 AM

Matt Engel

I've used this method many times! I also have it pull in other information from the UPS as well.  We several user defined fields in UPS that I access this way.  We have over 200 franchise offices that the user could be a member of 20 of them.  I use this method to pull in their preferred franchise (most recently used) and then a drop down list with the other franchises they can choose from as well.

Thanks Laura!
 on 6/29/2012 2:28 PM

Mark Wade

Very informative post. What if the PreferredName could not be the current login user.

For example, the people picker is populated by a managers group. But a manager is not allowed to approvetheir own  expense reports.

So the people picker should list all managers EXCEPT, the manager viewing the form? Any suggestions?

Thank you
 on 7/6/2012 3:07 PM

Laura

Hi Mark,
You could do something custom here.  create a new field, just call it PickedPerson or something.  Set the default value as the AccountID field of that people picker.  You can create a validation rule that will give an error if the picked person is equal to the AccountName of the currently logged in user.
lauraNo presence information on 7/17/2012 5:08 PM

Srinath

Hi Laura,

What I am trying to do is slightly different, asking you in case you can help me here.

I read a person/group field (note that they are repeating in nature) from a different list. I use double eval method to read all repeating fields and concat the AccountID, DisplayName  and AccountType  with a ";" respectively. The issue here is after I place those concatenated values in my current list in their respective fields, the person/groups do not get auto resolved. A simple tabbing and clicking outside the box resolves them.

 
 on 7/23/2012 8:09 AM
​I have disabled any new comments on this, because my blog has moved to a new site.  Please go here: http://www.wonderlaura.com
RSS FeedFacebookYouTube
 

 Our Books for End Users