Microsoft InfoPath 2010
The official blog of the Microsoft InfoPath team

Using the Contact Selector Control

Using the Contact Selector Control

Rate This

(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:

<Context siteUrl="http://<servername>"/>

**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 Heim
Support Engineer

Leave a Comment
  • Please add 2 and 4 and type the answer here:
  • Post
  • Hi Raj,

    InfoPath 2007 does not support promotion into a Person or Group field - what may work is to create another node in your data source (it does not need to appear on the view) and set the default value of this to either the Display Name or AccountId field and then promote this field. Obviously this will simply be a text data type and not a Person or Group field.

    Regarding how to populate the fields appropriately, you will need to set the value of the DisplayName and AccountId fields. The AccoundId is merely domain\user; however, in my testing it appears this is case-sensitive. As an example, the following does work for me:

    domain\user

    But what appeared in the Display Name field was: "FirstName LastName <domain\user>"

    Whereas when I changed this to:

    DOMAIN\user

    Then the only thing that appeared in the Display Name field was: "FirstName LastName"

    I would suggest for testing that you simply drag the Person group to your view as a Repeating Section with Controls, select a value using the Contact Selector control and you will see how these fields are populated.

    Scott

  • Hi,

    "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!"

    There is only one problem with this great idea and that is that ActiveX controls are not supported in template parts. At least that is what it says when I try.

    Andy

  • Hi Andy,

    My apologies for the confusion - what I was referring to was the process of creating the data structure needed for the Contact Selector control. You are correct - ActiveX controls are not supported but you can create the data structure so that all you need to do is add that template part to your new XSN and bind the Contact Selector control to that data structure.

    Scott

  • Hi Scott,

    Thanks for the reply,

    I figured out by trial and error on how to pre-populate the control, the same way that you mentioned.

    But still one of my problem remains.  What i need to do is perform a basic workflow on the submitted form.  Once the form is submitted, it is assigned to the user selected from the contact selector.  This part is done.  What i want to provide is the view to users so that they can only see the forms submitted to them.  I tried putting all possible values in the fileld (username, domain\username etc), but it still would not filter with [Me] or [Current User].  Is there any way to do this kind of filtering ???

    Thanks for your help,

    Raj

  • Hi Raj,

    Not trying to "pass the buck" on this but the filtering functionality is a feature of SharePoint - if this is not working as you need, you would probably be better served to post that question to one of the SharePoint groups.

    Scott

  • Is it possible to use the Contact Selector control on clients that only have InfoPath 2003 installed?  I have created a form in InfoPath 2007 and would like to allow users with only 2003 version to use it.  (Distribute/install the ActiveX control without having to install Office 2007?)

    -Thanks, Scott

  • Hi Scott,

    This is not a supported scenario - the Contact Selector control requires some 2007 files hence your users will need to have Office/InfoPath 2007 installed on their machines.

    Scott

  • More often than not, while working on custom workflow LOB (Line of Business) applications, we usually

  • More often than not, while working on custom workflow LOB (Line of Business) applications, we usually

  • Very Cool Control! But.... :-)

    How does one utilize more than one Contact Selector control on a form?

  • Hi neoearth,

    Assuming you have followed the naming conventions in this post, you have a group node named: gpContactSelector under the "myFields" node. To utilize another Contact Selector control:

    - Add a new group node under myFields named, for example, gpContactSelectorNew

    - Expand the existing gpContactSelector node

    - Right-click on the Person repeating node and choose Reference

    - Select the new group node, gpContactSelectorNew, and click OK

    - You should now see the Person node under gpContactSelectorNew - simply drag gpContactSelectorNew to your view and select Contact Selector!

    Scott

  • Hi Scott,

    Following up on the discussion regarding adding more than one Contact Selector Control to a form, I have a form and am trying to:

    - Add more than one (2 specifically...lets call them csA and csB) CS ctrl to each form, and

    - Perform a "required field" validation against both of these

    I've tried to implement this logic by using the technique you discussed on March 15 (remove the default form Submit feature & control the submit through a custom submit button with some conditional formatting). However, it doesn't work: when trying to make conditional formatting references to the 2 seperate DisplayName fields within the 2 seperate Person nodes of both the csA and csB contact selectors respectively, filling in *either* contact selector will cause the submit button to become enabled.

    In addition, we've tried other techniques, such as checking for fields (marked as required) associated with specific Person nodes, copying data to them using rules, and setting the default values to DisplayName node, amongst others. None of them seem to work (most of the form rules and field updates seem to trigger on submit, which is too late).

    Do you know, or can think of any way we can host more than one Contact Selector on a form *and* perform "required field" validation against both??

    Loving the blog, and thanks for your help in advance!

    Cheers, Brett

  • Hi Brett,

    I am not sure I am seeing the same behavior as you - here is what I tested:

    - Added 2 CS controls as per my prior steps

    - Added a button control to the View

    - Added the following Conditional Formatting to the button to disable the control:

    DisplayName -> Is Blank (this points to DisplayName under group1) or

    DisplayName -> Is Blank (this points to DisplayName under group2)

    If you then choose "The Expression" from the first dropdown box, my Conditional Formatting looks like this:

    my:group1/my:Person/my:DisplayName = "" (or)

    my:group2/my:Person/my:DisplayName = ""

    Now, if I Preview this form and enter a name in CS1, the button remains disabled. However, once I add a name to CS2 the button becomes enabled.

    Am I doing something in error?

    Scott

  • Hi Scott,

    No, you're doing it right, I'm an idiot! I just realised that the behaviour was not actually due to the contact selectors, but to something else I'd left in my overly complicated form from when I was trying to get it to work. When I replicated your test on a fresh form, it worked great!! Sorry I ever doubted! :)

    FYI, I've noticed that this technique will only work on the "first use" of the control; if you populate the control, and later clear it, required field validation will not be able to pick up the change, obviously because the DisplayName node still holds a value. It's not easy to clean this up without reverting to custom code, is it?

    Thank you very much for you timely help and assistance! Now loving the InfoPath blog even more!!

    All best, Brett  :)

  • Hi Brett,

    Glad you were able to isolate the problem! In regard to what happens after you clear the user from the CS control, you can better see this by dragging the "Person" node to your View as well. When you enter a user in the CS control and click the button to validate the user, you will see the associated fields get filled in; however, when you simply clear that user from the CS control those fields do *not* get cleared until you validate the user. Now - at that point, not only do those fields get cleared the node gets removed entirely. So, to make this work you will need to modify the Conditional Formatting on the button:

    Display Name is blank (for the first CS) (or)

    (Choose The Expression) count(my:group1/my:Person) = 0 (or)

    Display Name is blank (for the second CS) (or)

    (Choose The Expression) count(my:group2/my:Person) = 0

    What this will do is disable the button when: either control is blank or once you delete the user and click the button to validate the user.

    Short of this, you would need to write code to see if anything else would work.

    Scott

Page 2 of 27 (398 items) 12345»