Thursday, February 1, 2007

Contact Selector in InfoPath 2007

Procudure to create a Contact selector in InfoPath 2007.


  1. Open an infopath form in the design mode.

  2. Design Tasks -> Controls -> Add or Remove Custom Controls(locate this link at the bottom of the pane) -> Add -> ActiveX Controls -> Next -> Contacts Selector.-> next -> Don't include a .cab file -> Next -> Value -> Next -> From the Field or group type box choose Field or group (any data type)(*This is very important*)
    Click Finish
    Now the content selector control will be diplayed in the controls section.

  3. Now you need to create a schema that will host the Contact selector that we created in the above section.

    Design Tasks -> Data Source -> Select the 'myFields' and click on the Add a Field or Group(located at the bottom of the pane, under 'Actions'):
    Name : whatever you want (In my case, I named it as 'Grp_Contact_Selector')
    Type : Group
    OK. ( Do not check the 'Repeating' check box).

  4. Design Tasks -> Data Source -> Select the group name that you just created -> click on Add a Field or Group-> add a repeating 'Group' and name it 'Person'
    Name : Person
    Type: Group
    Check the 'Repeating' check box.
    OK.

  5. Select the 'Person' Group field and click on the Add a field or group, add 3 repeating fields under the 'Person' Group named 'DisplayName' , 'AccountId' and 'AccountType'.

    A. Creating the 'DisplayName' repeating field

    Select the 'Person' group, click on 'Add a field or group'
    Name: DisplayName
    Type: Field (element)
    Data Type : Text (string)
    Check the 'Repeating' check box.
    OK.

    B.
    Creating the 'AccountId' repeating field
    Select the 'Person' group, click on 'Add a field or group'
    Name: DisplayName
    Type: Field (element) Data
    Type : Text (string)
    Check the 'Repeating' check box.
    OK.

  6. C. Creating the 'AccountType' repeating field
    Select the 'Person' group, click on 'Add a field or group'
    Name: Account Type
    Type: Field (element)
    Data Type : Text (string)
    Check the 'Repeating' check box.
    OK.

    Once you are done with all the fields, your data source should look like the below image:




  7. Open Notepad and type the following text within the 'Context' node:


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





  8. Name the xml file as 'Context.xml'.


  9. Tools -> Data Connections -> add -> recieve data -> select the "XML Document" -> Next -> Click on the 'Resource Files' -> browse to the XML file that you just created and add to the data conections. Name the connection as 'Context'.
    Note: Name of the XML node in the file, Name of the data connection and name of the .XML file should be 'Context' (case sensitive).


  10. You are done! Now drag and drop the newly created Contact selector group onto the form. In my case, its 'Grp_Contact_Selector'.
    While dropping on the form, a popup will get displayed with various fields. Select the 'Contact Selector'.
    If you can't see the contact selector in the popup double check the above steps, especially the step 2.


  11. If you wanna see the selected contact selector in the infopath form library, then add this contact selector to the promoted fields(File-> publish -> site URL -> Infopath form lib name -> select 'Display Name' out of the above structure and function as 'First'. )


  12. Some times Contact Selector will grey out in the preview mode but you will be able to edit it in the actual 'New' Form.

Multiple Contact Selectors in Infopath 2007:
If you wanna have two or more contact selectors on a signle form, follow the below Procedure:





  1. Create the actual format of the Contact Selector Groups schema(Grp_Contact_Selector) directly under the myFields. We are done creating the 'Grp_Contact_Selector' group in the ablove section. So, I am not repeating the procudure here.

  2. Our goal is to create two more groups as the same hierarchy showed in the above picture, besides the original master contact selector group(Grp_Contact_Selector).
    To create the above hieracrchy shown in the figure follow the below procedure.

  3. Create two non repeat groups directly under the 'myFields'. Name it whatever you like. In my example, I named 'Grp_Proj_Manager' and 'Grp_Requester'.

  4. richt click on the master schema group 'Grp_Contact_Selector' group -> 'Reference' -> Browse and select the first folder i.e 'Grp_Proj_Manager'.
    (Now all the original master contact selector nodes hierarchy is copied under the 'Grp_Proj_Manager' group).

  5. richt click on the 'Grp_Contact_Selector' group -> click on 'Reference' -> Browse to the second folder i.e 'Grp_Requester'. (Now all the original contact selector nodes hierarchy is copied under the 'Grp_Requester' group).

  6. Now that you have two contact selector schemas under two different groups.
    All you need to do is to drag and drop the first group's referenced contact selector template (in my case its 'Grp_Contact_Selector') on to the designer.
    Important: Do not drag and drop the actual group 'Grp_Proj_Manager' or 'Grp_Requester' drag the referenced template instead. If you drag the actual group, there will not be any error but while filling out the form, after you select the user from the AD, contact selector field will be grayed out.

  7. Drag and drop the second group ('Grp_Requester') on to the designer.

  8. Now you have two different contact selectors that holds two names.

  9. In my example I explained 2 contact selectors. But, you can have 'n' number of contact selectors. Have fun!

7 comments:

  1. Ok this is cool but how would you go about making a view in a sharepoint list and group by Project manager? Now you have multiple DisplayName fields.

    ReplyDelete
  2. Create site columns to bind this display names and refer this columns in the filter/group by.

    While publishing the form, instead of selecting the 'create new column in the library' select the specific column. If you have multiple values in the display name, use the code behind to take the values into an array!

    ReplyDelete
  3. I tried to add two contact selectors into my InfoPath form, but when I open InfoPath form into browser, I am getting unknown error, in other side, I can open same form into InfoPath client, do you have any idea, what cause this problem?

    Thank you very much,
    Sanket

    ReplyDelete
  4. i'm getting the same error - can you help ????
    -----------------------------------------------------------------------
    ERROR MESSAGE:
    --------------

    Object reference not set to an instance of an object. at Microsoft.Office.InfoPath.Server.Controls.ContactPicker.RenderClientViewDataLeafContent(XPathNavigator context, IRenderContext renderContext, ControlViewData controlViewData, ScriptWriter writer)
    at Microsoft.Office.InfoPath.Server.Controls.LeafControl.RenderClientViewDataContent(XPathNavigator context, IRenderContext renderContext, ScriptWriter writer)
    at Microsoft.Office.InfoPath.Server.Controls.BaseControl.RenderClientViewData(XPathNavigator context, IRenderContext renderContext, ScriptWriter writer)
    at Microsoft.Office.InfoPath.Server.Controls.ContainerControl.RenderClientViewDataContent(XPathNavigator context, IRenderContext renderContext, ScriptWriter writer)
    at Microsoft.Office.InfoPath.Server.Controls.BaseControl.RenderClientViewData(XPathNavigator context, IRenderContext renderContext, ScriptWriter writer)
    at Microsoft.Office.InfoPath.Server.Controls.CollectionControl.RenderClientViewDataContent(XPathNavigator context, IRenderContext renderContext, ScriptWriter writer)
    at Microsoft.Office.InfoPath.Server.Controls.BaseControl.RenderClientViewData(XPathNavigator context, IRenderContext renderContext, ScriptWriter writer)
    at Microsoft.Office.InfoPath.Server.DocumentLifetime.Document.RenderResult(TextWriter writer, String viewState)
    at Microsoft.Office.InfoPath.Server.Controls.XmlFormView.RenderView(HtmlTextWriter writer, String viewState)
    at Microsoft.Office.InfoPath.Server.Controls.XmlFormView.RenderInline(HtmlTextWriter writer, String viewState)
    at Microsoft.Office.InfoPath.Server.Controls.XmlFormView.RenderForm(HtmlTextWriter writer)
    at Microsoft.Office.InfoPath.Server.Controls.XmlFormView.RenderContents(HtmlTextWriter writer)
    at System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer)
    at Microsoft.Office.InfoPath.Server.Controls.XmlFormView.RenderControl(HtmlTextWriter writer)
    at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
    at System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer)
    at System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output)
    at System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer)
    at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
    at System.Web.UI.Page.Render(HtmlTextWriter writer)
    at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
    Troubleshoot issues with Windows SharePoint Services
    -----------------------------------------------------------------------

    ReplyDelete
  5. It's not working for me.
    When i add the contact selector fields it's to a form and publish it to a sharepoint document library, the form won't open in the webbrowser.

    In infopath, when i select a user with a contact selector it will disable the contact selector and won't view the username.

    So this solution is not working for me. I'm going to search for another solution.

    ReplyDelete
  6. i get an error in the browser when i select the contact. right after i choose the contact and click ok i get an error "error occurred while trying to submit the form" although i did not click on submit yet!!

    any idea?!

    ReplyDelete
  7. The easiest way for multiple contact selectors:

    http://blogs.charteris.com/blogs/colinn/archive/2009/08/07/multiple-contact-selectors-on-an-infopath-2007-form.aspx

    ReplyDelete