(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 have a problem. I am publishing the InfoPath form (with contact selector control) in a SharePoint library. The value selected in the contact selector control does not appear in the SharePoint library. I have been trying to find the solution since morning but with no luck. While publishing 'DisplayName', i select 'first' function from the list of available functions. The 'DisplayName' property is created in the library but the value does not show. Any ideas?
That's odd - this works perfectly for me. In fact, I added both "Display Name" and "Account Id" as promoted columns and I see both get populated when I submit or save the form to the library.
For testing purposes, create a new form template with just one Contact Selector control and see if this works for you. If so, let me know what is different that is not working for you.
Is there any possibility that this might be happening because I am not on a domain? I am using a virtual PC and I am not on a domain. I am logged in as a local machine admin.
I am not sure - that may be the cause. I would test with just the form template created in this post just to be sure.
We are using the Contact Selector control on an InfoPath form that is being used as a Workflow Task form in a SharePoint 2007 workflow. The portal users are members of an Active Directory group named "Portal Members" and this group is a member of a SharePoint Site Group. The Contact Selector will allow the user to select anyone in the "Portal Members" group but unless the person selected is in the "All People" list on the portal they don't actually get assigned to the workflow task. I'm not sure if this is an InfoPath problem or a Workflow problem - any insight would be greatly apprceiated.
Actually this is a SharePoint control - I would suggest starting with that group. It may be a workflow issue but I am not sure.
Body: Para que septiembre no se vaya en blanco, aqui les comparto algo que nos anduvo dando algunos dolores
Para que septiembre no se vaya en blanco, aqui les comparto algo que nos anduvo dando algunos dolores
I made a contact selector. I want to select one ore more users, get their DisplayName and AccountID.
So far ok, but now, I want to add a CheckBox and a Dropdownlist to each selected Person. So I want to extend my contact selector so, that I can fill these extra fields. If I add these controls to the Contact Selector, these fields are dimmed, I cannot type in or select any values.
How can I do this using an other way?
Assuming you are trying to achieve a scenario where you can "select" multiple users, here is one way to get this to work:
- Modify your data source so that "group" for the Contact Selector control is under another "repeating group." For instance, here is how this Blog sample was designed:
- gpContactSelector (non-repeating group)
- Person (repeating group)
You could modify it like this:
- NewRepeatingGroup (repeating group)
- gpContactSelector (original non-repeating group)
- Person (original repeating group)
Then, under the new "NewRepeatingGroup" you would have your checkbox and dropdown list nodes. You could then drag the NewRepeatingGroup to your View and choose Repeating Table. This will add the Contact Selector fields as an "Optional Section." Just delete this and drag the "gpContactSelector" group to that first column and choose Contact Selector from the control choices.
Now, when you Preview this form you can enter a name in the Contact Selector control, validate it and the check box and dropdown lists are still available!
I hope this helps...
Thanx for the feedback, but it is not exactly what I wanted to do. :(
So: I have a contact selector. I fill this with names for example: marci737;infopath;chuck;teddy. The names are separated with ";". When I validate them, I want them to appear in a new repeating table so:
This would be the input for the next form.
There is no way in the UI to accomplish this - you will need to write custom code to accomplish what you are asking.
This works great for me - however, how do I set the default to be the current user? I know where to do this... DisplayName, right click properties, default. I just don't the formula or the value to put in there.
I am assuming that not only do you want to have a default user specified but that you also want that name "resolved" as if you clicked the "Check Names" button on the Contact Selector control - correct? If so, there are a few things you will need to do for this to work.
Clicking the Check Names button calls SharePoint's "people.asmx" web service to resolve the name. So in order for us to do this automatically, we will need to add this web service as a data connection, set the appropriate queryFields and then execute the connection. Here are the steps you will need to follow:
- Add a web service "receive" data connection to the "people.asmx" web service to your form template. NOTE: Make sure you uncheck the option to automatically get the data when the form loads.
- The URL for this will be something like this: http://server/_vti_bin/people.asmx
- Select the ResolvePrincipals method
- Complete the wizard
- From the Tools menu choose Form Options -> Open and Save
- Click the Rules button
- Click Add Action
- Set a field's value
- The field is named "string" from the ResolvePrincipals queryFields
- The value will be the "DisplayName" field from your Contact Selector data source (the default value for this will be domain\username)
- The field is named "principalType" from the ResolvePrincipals queryFields
- Copy and paste this as the value: User SecurityGroup SharePointGroup DistributionList
- Query using a data connection
- Data connection: ResolvePrincipals
- The field will be the DisplayName field from your Contact Selector data source
- The value will be the DisplayName field from the "dataFields" of your ResolvePrincipals data source
- Repeat the above action to set the following fields:
- AccountId from Contact Selector equals AccountName from ResolvePrincipals dataFields
- AccountType from Contact Selector equals PrincipalType from ResolvePrincipals dataFields
So now if you set the default value of the DisplayName field to domain\user, it should auto resolve when the form is opened.
I hope this helps!
Wow, lots of information here, thank you! I followed your instructions exactly and everything you said was where it was supposed to be, very impressive.
It appears to be working by doing the user check, but how do I get the default value to read the Current User who is filling out the form?