(This post applies to InfoPath 2007. If you're using InfoPath 2010, then you should check out this post instead.)
We have seen a number of requests on how to allow a user to enter (or select) a person’s name or logon alias and then validate that user against their Active Directory without using code. This has been especially true in workflow scenarios where User A needs to enter in the name of User B – the next person in the workflow process.
Well, InfoPath 2007 ships with a control called Contact Selector Control that will resolve these issues! You may have seen our older article on the subject; this one aims to dive in deeper.
The Contact Selector control is an ActiveX control but it is a special cased control, in that it can also be used in InfoPath browser forms. To use this control there are specific steps that need to be taken – let’s take a look at those now.
Step 1: Add the Contact Selector control to your Controls Task Pane
1) From the Controls Task Pane click the Add or Remove Custom Controls link
2) Click the Add button
3) On the first screen of the Add Custom Control Wizard select ActiveX control and click Next
4) From the list of controls, choose Contact Selector and click Next
5) Select “Don’t include a .cab file” and click Next
6) For Binding Property select Value and click Next
7) From the Field or group type box choose Field or group (any data type) and click Finish
8) Click Close and then click OK
Step 2: Create the data structure for the Contact Selector Control
The Contact Selector control needs to have a specific data structure to work properly – this is documented on the “Items” tab of the Properties screen for the control; however, we’ll include that information here as well.
**IMPORTANT!** Spelling and capitalization must be exactly the same, starting with the “Person” group!
1) Add a non-Repeating Group named: gpContactSelector
2) Add a Repeating Group named: Person
3) Add the following 3 text fields to the Person group: DisplayName, AccountId and AccountType
Step 3: Add and bind the Contact Selector control to the View
1) Drag the gpContactSelector Group to the View and select “Contact Selector” from the list of controls
2) You’re almost done…! :-)
Step 4: Add a secondary data source XML file which specifies the SharePoint server
The Contact Selector control needs to know the “context” of where the user validation should occur. These steps are not necessary if you are only displaying the form in a browser from SharePoint – in this case, it uses the context of the site from where it was provisioned; however, if you are in a mixed client/browser scenario you will need to include this XML file so forms opened in the client can use this functionality.
1) Launch Notepad
2) Copy and paste this one-line XML:
**NOTE: Replace <servername> with the name of your server
3) Save this as: Context.xml (again – naming and capitalization are important)
4) Add Context.xml as a “Receive” type Secondary Data Connection to your form template and make sure the option “Include the data as a resource file” is enabled
Step 5: Test!
You should now be able to Preview the form, enter a name or logon alias, click the “Check Names” button and resolve the name! Alternatively you could click the “To” button to perform a Search if you do not know the complete name of the user.
One other important point: if this control is something you will use numerous times, this process works great to create a “Contact Selector Template Part” – then you only have to complete these steps one time!
Scott HeimSupport Engineer
I've checked it. All the groups that I am using with contact selector have the same structure, including correct spelling and capitalization, as it's specified in the post.
Can you check and make sure you can successfully validate a user with the built-in "People Picker" control in SharePoint? Try these steps:
- Navigate to the same site you are trying to use with InfoPath
- From the Site Actions button, choose Site Settings and then choose People and Groups
- Click New
- Enter the same name in the Users/Groups box and click the "Check Names" button...does that user get validated?
If so, are you testing the control in the InfoPath client or in the browser? If you are not testing in the browser, please publish the XSN to you site, open a new instance of the form in the browser and what are the results of the control here?
Great instructions! Thanks. In testing the instructions there is an error submitting the form when I click to resolve the name.
I went back to the template and ran the design checker and got "The SOAP message could not be parsed"
The first thing I would do is start over with a new, blank XSN and insure that you have named *everything* identical (including capitalization) to what I have here in this post. Then test and see if you have any different behavior - most issues I have seen stem from either the data source not being constructed correctly or the names not be either spelled/capitalized correctly.
Have you reolved the Firefox and Safari issues? It has been a few months and you have had sufficent time to resolve these problems. Please provide a link to the hot fix or service patch.
The Contact Selector generated by ContentType schema throws AccountId as an integer (which is User Id), it doesn't gives the username.
Has anyone come across this issue? I will appreciate if Scott or anyone can help me on this. I am nearly there and just stuck on this problem.
Thanks in advance.
Is this InfoPath 2007? Also - when does the error occur? I need a little more detail on what you are doing when the error occurs.
About the bug in FireFox/Safari... interestingly enough SP2 fixes the peoplepicker control within general SharePoint, like if you add New Users to a group or such. It used to have exactly the same buggy behaviour where it didn't work in those browsers, and it's been resolved.
But looks like the hotfix doesn't affect where InfoPath renders the control in forms. So even with SP2, you can't correctly start a Review workflow against a document on the Workflow Initiation Form, as this is rendered by InfoPath. Pity the fix didn't apply to both instances of the control!
Scott, I guess we don't have any idea if they could use that hotfix against the InfoPath version do we? :(
I am unsure if the same fix could be used in the Contact Selector control that was used in the SharePoint People Picker control. However, although a fix for this did not make it into SP2 it is something we are looking at for our next version.
I presume you mean next version SP3, or possibly hotfix before? Not next version 2010 :) (I hope!)
"Next version" is 2010 - this is where we are looking to try and correct the behavior.
ok.. first fo all thank you.
my problem is a little strange. i added the contact selector and it works. i click "To..." and i search for the contact and i get results, i select a contact and click add then ok. and BOOM error submitting the form!
i did not submit the form!! i simply clicked OK after choosing my contact!!
all that is in the browser form, but on the local machine, also everything works up to the point where i click ok after selecting the contact, then the contact selector turns gray and if i submit the form the corresponding column in the library is empty.
i need your help on this one and i appreciate it :)
thanks in advance
If the Contact Selector control turns "gray" then the only time I have seen this occur is when you do not have the data structure setup correctly *or* the node names spelled correctly...including capitalization.
Please compare the spelling of your node names to what is documented in this blog and make sure they match EXACTLY what is shown here.
here is a copy paste of my nodes names:
i don't see anything different here. and here is the context file line
as i said, it does get the search results correctly, and problem happens when i click OK after selecting the contact.
The "Person" node is not spelled correctly...assuming that was just a typo when you entered here in your comments, then the next step is to make sure you have the node types correct:
Person - this is a "Repeating Group"
AccountId, AccountType and DisplayName are just "Field (element)" data types