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 1 and 6 and type the answer here:
  • Post
  • Hi caseycase,

    Glad that helped!

    Try this:

    - Remove the hard-coded user name from the default value

    - Click the "fx" button

    - Click the Insert Function button

    - Select the All category

    - Scroll to the bottom of the Functions list and select userName

    - Click OK until you are back to your form

    - Test! :)

    Scott

  • That worked!  Thank you very much - thank you especially for responding so quickly.

  • Glad to help!

    Scott

  • Hi arttu_123,

    In regard to your question of using the Contact Selector control in a Document Information Panel - I don't know that I am seeing the same results. Here are the steps I followed:

    - Created a new Document Library named: ContactSelectorTest

    - Enabled the option: Allow management of content types

    - Added a new column to this library named: Responsibilities and set the data type to Person or Group

    - Clicked the Document Content Type and selected Document Information Panel settings

    - Clicked Create a new custom template

    - Reviewed the data source and it matched what you are seeing:

    p:properties

     :documentManagement

        ns2:Responsibilities

           UserInfo

              DisplayName

              AccountId

              AccountType

    - Published this back to my library as a Document Information Panel (default option)

    - Clicked New to create a new Word document

    - Entered my user name in the Contact Selector control and clicked the "Check Names" button - result: resolved my name

    - Clicked the Add people from Address Book button, entered a co-workers user name, clicked the Go button, selected that user, clicked Add and then OK - result: that user's name was displayed in the Contact Selector control.

    Am I doing something differently than what you are trying to accomplish?

    Scott

  • Hi,

    Brilliant post, helped me loada already! :)

    Relly annoying that you can't promote to a person or group field in SP however..

    So I wondered is there a way to get the actual email address instead of the account ID or display name? I think this would look better in a column instead of the account ID.. but is it possible? :)

    Thanks!

  • Hi thunderstorm,

    The Contact Selector control will only be able to obtain the data for those fields that you see in the data source. You may be able to use the value returned in the AccountId field to query your Active Directory to return this information.

    The other possibility is if you have a configured profile database, pull the information from here as well.

    Scott

  • Hi Scott

    Very nice post here, helped me alot.

    I have the folowing issue: I'm trying to use Contact Selector on a Modification Form for my workflow.  When I want to add a new Contact on that form, it gives me the following error: "'my' is an undeclared namespace: Line 1, Position 2" + StackTrace.

    Thanks!

    Anca

  • Hi Anca,

    Does the same error occur if you simply double-click (launch) the InfoPath form outside of your workflow? I just want to be sure this is not specific to your workflow process.

    In short, it sounds like you are maybe using code to reference one or more nodes and have not declared the appropriate namespace.

    Scott

  • Hi Scott,

    Sorry I was so brief in my last post.

    Basically I tried to deploy the form in a non workflow context, just publish the form and then test it. It works (both in infopath and browser) , so it's not something strictly related to the form !

    In the stack trace I can see that AppendChild() is called and with that also NamespaceLookup() and that is where the exception gets thrown.

    I don't really understand because the same methods are called when I test my form in a non workflow related environment, and it works.

    Thanks,

    Anca

  • Hello Scott,

    Actually when creating a new document information panel for that content type, I've been editing the current template, instead of creating a new one, otherwise I've been doing the same as you - appearantly with different results.

    However, I followed your steps to the letter on our staging site, and everything worked flawlessly and the contact selector works properly. The same method did not work on our production site though.

    When I try to create a new custom template I get an error message that I self atleast cannot interpret:

    "InfoPath cannot open the following form: C:\Documents and Settings\username\Local Settings\Temporary Internet Files\Content.MSO\D60BC53.tmp\customXsn.xsn"

    And in details:

    "The form definition (.xsf) file contains elements, attributes, or structures that are not valid.

    Error details:

    'list_' is a duplicate key for the unique Identity Constraint '{http://schemas.microsoft.com/office/infopath/2003/solutionDefinition}dataObjects_name_unique'.

    Line 155, Position 4

    </xsf:dataObjects>

    ---^"

    I'm all baffled about this message and I've been trying to fix it myself.

    Oddly enough I've been having lot's of problems with InfoPath when working directly with our production site and none when working with any other web application.

    So the main problem isn't fixed yet though. I've been editing the current xsn template and manually added the contact selector control there and binding it to the Responsibilities data source. I can still type in some text to the text field and browse through the address book. But when I either try to click the 'Check names' or after cliking OK in the address book, nothing happends - nothing appears in the text field.

    I'd think that the contact selector would start working properly aswell if I could get that "Create new custom template" working. I just hope that it's some small strange bug and not something with the whole web application.

    Thanks in advance,

    Sebastian Eriksson

  • Anca - have you added custom code to your form? Are you 100% sure this code gets executed in a non-workflow scenario?

    Sebastian - what happens if you create a new test document library and attempt to create a new custom template - do you still get the error? I am wondering if this is site or library specific?

    Scott

  • Hello Scott!

    Ah yes, it does actually work when I create a new document library in the same site. Well I guess this solves my problems then, a bit work to add all the columns and content types to the new library, but nothing too much. The cause of that error still eludes me though. But hey, all that matters is that it's working now :)

    Thank you

    Sebastian

  • Hello again,

    I actually figured out why I kept getting that error message when trying to create a new custom template in a document library. One of my custom content types used in that document library uses two lookup colums which get the information from another list in my sharepoint site. For some reason when I create a new template, InfoPath sets the data source for those columns as a list named just "list_", and it only has a value @ID, nothing else.

    And when I had those two lookup columns in one content type they both used the dataObject name 'list_'.. hence the "'list_' is a duplicate key for the unique Identity Constraint" error. I can get it properly working when I remove the second lookup column from the content type and manually readjust the data source of the first lookup column after "Create a new custom column". Do you think this is a bug or just something with my site collection?

    In short: I have two sharepoint lists and one document library with a custom document content type that has lookup columns to fetch information from those lists. InfoPath sets the data source for these columns wrong, when trying to create a new DIP template for the document content type.

  • Hello Scott,

    No, my form has no custom code in it. My form only has a contact selector configured as you described it here, and a Submit button.

    I designed this simple form to use it in order to reassign a task to another person in a workflow. So when I try to add a contact in the control it shows me that error.

    I'm sure it works in a non workflow context.

    Thanks,

    Anca

  • Sebastian - that is great to hear that a new library works. Like you, it is interesting as to why the original did not but at this point, it is probably not worth spending a lot of time trying to isolate the cause.

    arttu_123 - thank you for the update! I am not sure if this would be expected or not - if you would like to pursue this, I would suggest opening a support case and please provide us with the steps to reproduce the behavior. It sounds like it could be an issue so we should probably look into this further.

    anca_accenture - thank you for the additional information. Can you confirm something for me: if you remove the Contact Selector control from the form, it then works in your workflow?

    Thanks all,

    Scott

Page 5 of 27 (398 items) «34567»