Abhishek Bhowmick | SharePoint Blog

Using a Contact Selector/People Picker in an InfoPath Form

Posted in Sharepoint by Abhishek Bhowmick on September 9, 2010

Using the People Picker functionality in InfoPath 2007 that SharePoint 2007 supports natively.


Note that the example below assumes you are using InfoPath 2007 and that you have access to a SharePoint server.

Create a new form in design mode

Open the task pane by clicking View >> Task Pane in the toolbar.

Select Controls in the Design Tasks window

If you do not see the contact selector under Custom you will need to add the ActiveX control for the first use. Scroll to the bottom and select Add Remove Custom Controls.

Select Add or Remove Custom Controls… and the custom controls window will appear. Select Add.

Choose ActiveX Control

Do not include the cab file

Select Value in the bind to property

Select Field or Group in the Specify Data Type Options screen

Now that we have successfully added the contact selector to your available InfoPath controls let’s go ahead and add the control to our form

Now comes the most critical part but if you follow the steps perfectly, you should be result with flying colors. We are required to create a data structure with the following schema which a contact selector expects somewhat like the below to bind the control to where the data is stored. However, please keep in mind that they are all case sensitive.

Go back to the Design Tasks and select Data Source

Right click under myFields and select Add

Type in the Name as gpContactSelector and select the type as Group. Ensure that this group is NOT a repeating group. This will act as the parent group to which the Contact Selector control will bind to. Click Ok to Add.

Now right click gpContactSelector and click Add.

Type in the Name as Person and select the Type as Group. Make sure this is a Repeating type group. Click Ok to Add.

Now we will add the String type Fields attributes (DisplayName, AccountId, AccountType) under Person. Make sure you keep right clicking the Person group field and select Add for all three string type Fields else the schema would mismatch and the functionality will work.

Type in Name as DisplayName and select Type as Field (element) and Data type as Text (string). Leave the Default value as blank. Ensure this is NOT a Repeating type group and the option Cannot be blank (*) is unchecked. Click Ok to Add.

Type in Name as AccountId and select Type as Field (element) and Data type as Text (string). Leave the Default value as blank. Ensure this is NOT a Repeating type group and the option Cannot be blank (*) is unchecked. Click Ok to Add. AccountId (note the “d” is lowercase)

Type in Name as AccountType and select Type as Field (element) and Data type as Text (string). Leave the Default value as blank. Ensure this is NOT a Repeating type group and the option Cannot be blank (*) is unchecked. Click Ok to Add. AccountType (note the “T” is uppercase)

Once all the three as above are done, you data structure would look like as below

We are almost done and we will now add the Contact Selector control to the InfoPath form body thus binding it to the gpContactSelector (non-repeating type group). To do this just right click and hold on gpContactSelector group and drag it to the body of the form and release the click. It should present you with the following list of menu as below. Select Contact Selector and we are done.

Once the control is added to the form, it should look something like this.

Now for the last step, we will need to configure a secondary data source for the server context. We will first need to create an XML file called Context.xml as required by the contact selector.

Open Notepad and type in the following: <Context siteUrl=”https://sharepointserver”/&gt;. You may replace the sharepointserver with your server name or name of the web application where your SharePoint site is hosted. Note that this is case sensitive and the syntax should be absolutely identical. Save the file to your local hard drive as Context.xml (case sensitive)

Now we will need to add this file as a Data connection to receive data. To do this go back to your InfoPath form and click on Tools >> Data Connections.

Add a new data connection to receive data

Select XML document

In the XML data file details window select Resource Files and add the Context.xml document you previously created on your local drive.

Leave the name as Context

Complete the Wizard

Your form is now all set to be published. Please note you will need to publish the form template as browser enabled to your SharePoint form library and allow the option to open as web page in the form library advanced settings as below.

Common errors to be avoided at all costs:

  • Remember that the data source for Context is receive.
  • Make sure the Context.xml is well formed (the context tag must have an end tag)
  • Make sure the data source is named Context
  • Make sure you spelled all of the field names correctly
  • Make sure that the person field is repeating
  • Validate the binding of the contact selector control, it should bind to the parent of the Person group

2 Responses

Subscribe to comments with RSS.

  1. David said, on April 29, 2011 at 8:28 pm

    Your example works where others have fallen off the mark.

    Any chance to pull other data points such as Title and E-Mail? These show in the People Picker but adding the fields to the data element did not work. Is there another method?

    Thanks so much!

  2. Phil said, on December 22, 2011 at 5:21 pm

    I’ve been to 6 different sites concerning the use of the people picker selector and they all say to bind the control to the parent of the Person group.

    You cannot do this…as a matter of fact, you cannot bind any control to a group.

    Please do let me know if I’m wrong on this matter.

    Also, I get a very irritating error message after I have selected a user from the people picker…this is it:

    “The element ‘http://schemas.microsoft.com/office/infopath/2003/myXSD/211-12-09 blah blah blah… peoplePicker’ cannot contain child element ‘http://schemas. blah blah blah…. Person’ because the parent element’s content model is text only.

    I have gone through everything 10 times (and an extra time on top of the extra time…and more) but do not see typos, etc….

    Please help

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: