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 1 and type the answer here:
  • Post
  • actually no, it was not a typo, it was a copy paste from my elements. and that was the problem. now everything works great

    thank you so much.. i know i look stupid specially that i read most of the comments and not just on this site, but on other and i was telling my self, guys please make sure your elements names are correct before you assume there is something wrong! lol this is really embarrassing.

    anyways, please accept my apologies. and i need your help on something else.

    in the form im creating i need to have multiple contact selectors.

    1-To.  

    2-Addressed To.

    3-CC.

    4-From.

    5-Secretary

    i tried to use the same steps here to create a template but when i try to add the Contact Selector activeX controlit says

    "the custom control you have added is not compatible with the form template or template part, and will be hidden in the controls task pane."

    any suggestion!?

  • No problem - glad it was that easy! :)

    In regard to multiple controls, take a look at my comments from May 22, 2007...

    Scott

  • scott,

    that is great, thank you so much.

  • Hi Scott,

    I'm new to creating XML files and I have the following error "The 'Context' element is not declared."

    I added the control to the form and publish.  When I select the To button, type a name, click Go, and it shows the control searching, then I get an Search failed message.

    Do you have any idea what may cause this?

    Thanks,

    Nichelle

  • Hi Nichelle,

    My apologies for the delay in responding as I was on vacation. :)

    Have you resolved the "Context" element error yet? If not, then honestly no, I have not seen this error before. Did you follow the steps in this blog exactly as they appear?

    Also - what version of InfoPath are you using?

    Scott

  • Hi

    I'm creating a new form and read your article, but when doing the preview and click the "to" button I get a window with no names. I guess I'm not pointing the XML file to the right place. What should the server format be like?

    This is my outlook server:

    GVW1162EXB.americas.hpqcorp.net

    Also, does is have anything to do, that I haven't pubilshed the form yet and that's why I don't see any names appearing when I click on the "To" button?

  • Hi namariegaudi,

    The URL in the context.xml file needs to point to your "SharePoint" or MOSS server - not an "Outlook" server. So if you want to use your root site collection of your server, the XML file would be as described in this blog:

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

    However, if you wanted to use a subsite, it would be like this:

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

    Scott

  • Great!!! it works!!!

    One final question though...if I need separate emails fields to be added do I need to redo the steps described above or I can just copy the Contact Selector to other places?

  • Hi namariegaudi,

    You cannot just "copy" the contact selector elsewhere and get it to work...take a look at my comments from May 22, 2007 for how to add multiple contact selector controls to one InfoPath form template.

    However, if you just need multiple selections, you may want to look at putting the contact selector control in a "repeating" section or table and then use a custom function to pull all the addresses. For this scenario, take a look at my April 30, 2009 comments.

    Scott

  • I want to create a "workflow" the requestor, enters their email and data for approval along with a first level approver & a second level one. Once the requestor enter all data. I want an email sent to the 1st level requestor either approving the project. If approved, then I want the email going to the 2nd level approver.

    If both values are "approved" then requestor gets an email notification. If at some point 1st or 2nd level approvers reject the data another email will inform the requestor. Can this be done via rules in InfoPath? FYI, I'm not using contact selector for requestor's email...only for 1st & 2nd level approvers

  • Hi namariegaudi,

    Yes - this should be doable using Rules in InfoPath.

    Scott

  • Scott here's what I did, but it doesn't seem to work. Need help.

    1. I selected the person group abd clicked on properties

    2. Added a condition that AccountId is not empty. Should it be a condition that AccountId, DisplayName & AccountType shouldn't be empty?

    3. I setup an Action to submit email via a data connection

    4. My data connection has as receiver the gpContactSelector and I'm sending the form in active view (not as an attachment)

    For some reason when entering a project in the form and saving it in SharePoint the rule doesn't start and hence no email is sent. Am I missing something?

  • Hi namariegaudi,

    I misunderstood how you were doing this...I didn't understand you were trying to add a Rule to the Contact Selector control. As you can see, that won't work. Normally what is done is, after everything is filled in the way you want, you have a Rule on a "button" to submit the form, send the mail, whatever. Then in the condition for this Rule, you can make sure that whatever fields are "required", they are not blank.

    Scott

  • Hi Scott,

    I am having a wierd problem and I am kinda stuck. I have got SharePoint DIP in InfoPath bound to a SharePoint content type. Now there is a field of type User in that CType, InfoPath automatically created a people picker, issue is the AccountId stored in this field is the interger id of User Information List and not the account name because the inline type of that field is dms:UserID and not xsd:string. Because its an interger and not accountname I can't call GetUerprofileWebService. So I tried getting the accountname from UserInformationList using the accountid, however if I lookup a user using people picker and if that user has not accessed the site before he desn't exist in UserInfo list which means my GetuserProfileService method fails.

    Would you have any workaround for this? I will be very thankful if we can get a workaround for this problem as my system is nearing an end.

    Thanks in advance,

    Kunal

  • Hi Kunal,

    The only way I can think of to get this to work in cases where a user has not accessed a site yet, would be to create a custom web service that would take the "Display Name" of the selected user, find that user in Active Directory and then return the associated information about the user that you need. In other words, you would be using your own "custom" process to get the user's information.

    If not, then the only way I know if is to convert the SharePoint ID of that user to the appropriate account but as you noted, this will be an issue if the user has never accessed the site before.

    Scott

Page 24 of 27 (398 items) «2223242526»