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.

Procedure:

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
Advertisements
%d bloggers like this: