Pallierer @ SharePoint UserGroup



Using Active Directory Information in Infopath and Forms Server (Part 1) 

Tags:

With InfoPath 2007 there is a new function introduced which allows us to get the current username without any .NET coding. Simply use the username() default value box to fill a text box with the username:

dysnap_001

The good thing is: it's very easy to use without any coding and works in InfoPath 2007 as well as in SharePoint Forms Server solutions. But the bad think is: only the username can be used - no information about email (e.g. for Workflows), manager, phone, fax information. But there are two ways to overcome that limitation:

  1. integrate MOSS User Profile Store (UPS) into InfoPath (requires MOSS and a running Sync job between AD and UPS)
  2. integrate Active Directory into the InfoPath solution (requires nothing but an Active Directory Domain)

let's start with 1):

Integrating Active Directory Data into InfoPath using the MOSS 2007 User Profile Store

Another way is to use the OOB MOSS 2007 Web Service. MOSS 2007 comes with a nice technology called User Profile Store (UPS) which "extends" Active Directory with the User Metadata for SharePoint. The nice thing is that you can sync the UPS with the Active Directory. You can find the Mapping Definition in the SharePoint Central Administration at "Shared Services->User Profile and Properties->View Profile Properties"

image

As soon as we imported the AD Data into the USP, we can access the User data via the MOSS Web Services. The Web Service for the UPS  can be found at http://[Servername]/_vti_bin//UserProfileService.asmx.

So - let's get started to use the web service from InfoPath.

First start with a new blank form template. Add a blank text box to the form and name it "Username". Then add the Web Service to the UPS to the secondary Data Sources (Tools->Data Connections->Add) as Receiving Data Connection to a Web Service as http://[Servername]/_vti_bin//UserProfileService.asmx?WSDL

image
image 
image 

After that you get a list of the available Web Methods - the Method GetUserProfileByName is the one which helps us:

image

as you can see the Web Service only expects one parameter - surprise, surprise - the Account Name of the user we are looking for. (in the form DOMAIN\AccountName)

image

On the last page uncheck the "Automatically retrieve data ..." box, because we want to call the web service manually.

image

That's all ! All we have to do is to supply the web service we registered before with a parameter (Account Name), call the web service and display the result.

The best place to call the web service are the Rules of the Textbox (Username) - they are called whenever the value of the textbox changes.
To modify them double-click on the textbox and the property page opens - here you can find the rules button:

image  

Add a new rule which consists of two actions - the first sets the parameter of the web service and the second calls the web service. The magic part is that you don't set a field of the Main Data Source - you must set the query fields of the secondary (=web service) Datasource.

image

The value we want to use is - of course - the textbox:

image

After setting the query value of the web service - call it !

image

 

The last thing we must do - is to display the data. The best control for that is a Repeating Table. So add a Table Control to the form (change the number of columns to 2)


image

Now we change the binding of the table to  the result of the secondary datasource (=Web Service).

image

image image

 

And now - let's test it:

image

 

The warning Page comes from InfoPath whenever you access an "untrusted" data source - you can avoid this by signing and trusting the form (http://msdn2.microsoft.com/en-us/library/Bb251020.aspx)

In a view days i will show you how you can use a custom web service to access the same data direct from the Active Directory

 

 
Posted by ppallierer on 24-Aug-07
0 Comments  |  Trackback Url  |  Link to this post | Bookmark this post with:        
 

Comments

Name

Url

Email

Comments

CAPTCHA Image Validation