.Net & SharePoint '07

Technical blog for .Net and all SharePoint 2007 related Information

About the author

Me(Prince) and my wife are B.E in I.T & C.S.E respectively.  I a certified MCPD: Web from 2007 Dec. I am Intrestes in Web Application, MOSS, EPM, etc.
Now working with Deira International School, as IT Application & Help Manager. I have started my career as "Software Developer" @  REACH Sewn Technologies and Consulting Pvt. Ltd, Bangalore India from Oct 2004 to Feb 2006, then as "Web & Intranet Developer" @ Fosroc International Ltd, Dubai from April 2006 to Sep 2009.
You can catch me on mail@jpy-tech.com or mail@princepy.com. Or on 00971 - 50 - 4284530 

Google Translate

Tag cloud

Calendar

<<  May 2012  >>
MoTuWeThFrSaSu
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

View posts in large calendar

RecentComments

Comment RSS

Google Your Location


Using the Contact Selector Control & Population Default User

Using the Contact Selector Control

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.

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!

Source: blogs.msdn.com/infopath

Filling / Selecting Specified User as Default Value for Contact selector

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.
  • 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)
    • Click Add Action
      • Set a field's value
      • The field is named "principalType" from the ResolvePrincipals queryFields
      • Copy and paste this as the value: User SecurityGroup SharePointGroup DistributionList
    • Click Add Action
      • Query using a data connection
      • Data connection: ResolvePrincipals
    • Click Add Action
      • Set a field's value
      • 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.


Posted by admin on Tuesday, September 23, 2008 3:19 PM
Permalink | Comments (0) | Post RSSRSS comment feed