call 905-370-0333
Live chat

How To: Import data from Active Directory to an InfoPath 2007 Form Template (code free)


Want to fill in forms without having to use InfoPath or code?

In this article KWizCom's Shai Petel will teach you how you can maximize the out of the box features of Microsoft products to create excellent customer-specific solutions.

MOSS has a great new feature that allows (among other things) the publication of InfoPath forms to the server and thus enabling users that do not have InfoPath installed to fill in forms without having to distribute or purchase InfoPath for each client.

One of the things everyone who has asked me about this have in common is that they all work in a Microsoft Active Directory environment and they all want their form to load Meta data from the current user and populate their form with that data. Now, InfoPath and AD do not have a method for creating a direct connection, but since all of our users also utilize the Microsoft Office SharePoint Server (MOSS) forms server they can take advantage of other features and capabilities of MOSS to solve this problem.

MOSS connects to your AD easily and builds a user profile based on the data stored in AD for each user. This part is easy enough to perform so I will not elaborate further on that here.

Once your MOSS “recognizes” your users, you can make use of its web services to retrieve all users list, a specific user profile and also the current user profile.

Here I will demonstrate how to create a form that loads current user profile data as stored in AD without writing a bit of code.The only thing that needs to be done is to define a connection to a certain web service that already exists in your SharePoint site out-of-the-box (OOTB).

Step 1: Create a blank form template

  1. Click FileDesign a Form Template
    The 'File' menu, with the 'Design a Form Template...' item highlighted
  2. Select Blank
    The 'Design a Form Template' dialog, having the 'Blank' option selected
  3. Click OK

Step 2: Setting up the web service connection

  1. Create a new data source connection.

    Go to ToolsData Connections...

    The 'Tools' menu with the 'Data Connections...' item highlighted
  2. In the Data Connections dialog, click on Add...
    The 'Data Connections' dialog, having the 'Add...' button with keyboard focus
  3. In the Data Connection Wizard dialog, select the options Create a new connection to: and Receive data. Then click Next
    The 'Data Connection Wizard' dialog, showing the selected=
  4. Select Web service as the source type
    The dialog prompting for a data source with the 'Web service' option selected
  5. Insert the following web service name: http://<servername>/_vti_bin/userprofileservice.asmx?wsdl (replace <servername> with your SharePoint server name) and click Next
    Prompt to 'Enter the location of the Web service you want' etc.
  6. From the Select an operation drop down list select GetUserProfileByName
    Prompt to 'Select an operation', with the 'GetUserProfileByName' option highlighted
  7. In MOSS, calling this operation without sending a user name will return current user's profile.
  8. Click Next. Keep clicking Next, preserving the defaults in every screen, and finally click Finish.
    The 'Data Connection Wizard' dialog final step
  9. Close the Data connection window.

Step 3: Viewing and choosing the AD details we wish to import:

Now, we need to insert the AD information to the correct fields. To do so, we first need to see what kind of data we can use.

Since the users profile may include different properties according to your organizations' software and other dependencies, the web service results returns a set of “name-value” collection that we can use in order to get the results we need.So – first, we have to find the “name” of the property and then we'll use it to get its value from the web service.

Here is how it is done:

  1. To see all the available fields click on ViewData source
    The 'View' menu, with the 'Data Source...' item highlighted
  2. In the Data source drop-down select the one we just created.
    Select the 'GetUserProfileByName (Secondary)' option from the 'Data source' drop-down selection box
  3. Expand the dataFields container node and select the following fields in the results:
    The property tree showing 'PropertyData' suboption of 'GetUserProfileByName' highlighted
  4. In the drop-down menu on the selected nodes select repeating table and place it in the form.
  5. You now have a repeating table with all data returned by the web service. To see all the AD fields available to you, Click Preview in the tool bar.
    The toolbar with the 'Preview' button hightlighted
  6. Now, locate the property you need and copy its name
    A 'repeating table' displaying properties of the user profile
  7. Return to the design mode by clicking Close preview.

Step 4: placing the AD details in the controls:

Now the only thing left for us to do is place the field we chose earlier (in step 3) and define the control to show that field's info.

  1. In the form, double-click the control you wish to fill
    An InfoPath 2007 'userName' control
  2. In the control properties click on Function Editor button to open the function editor
    The 'Text Box Properties' dialog with the 'Function Editor' button highlighted
  3. Then click on Insert Field or Group...
    The 'Insert Formula' dialog
  4. In the next window, select the data source you created
    Select the 'Value' field from the 'GetUserProfileByName (Secondary)' data source
  5. Expand all the folders under DataFields until you can see and then select the Value node.  

This inserts one of the “values” we got in the web service response. Now we need to enable it to “filter” the values by the property name we want. To do so:

  1. Click on Filter Data button. In the pop up window click Add...
    The 'Filter Data' dialog
  2. In the next window select the Select a field or group... option
    A drop-down list with the 'Select a field or group...' option highlighted
  3. And select the Name node from our service data source:
    Select 'Name' field from the 'GetUserProfileByName (Secondary)' data source
  4. Click OK. Then Select Type Text and enter the property you copied in the previous section as the value
    The 'Specify Filter Conditions' dialog with the condition set to 'Name' is equal to 'PreferredName'
  5. Click OK to confirm and close all the pop-ups.  
  6. Click Preview in the tool bar to see the results.
    The toolbar with the 'Preview' button hightlighted
    A Microsoft Office InfoPath form showing the Active Directory preferred name in the 'Name' field

Now your form displays the user preferred name as it was entered in the AD and all that without writing a single line of code!

Important: Your document must be fully trusted in order to execute the web service correctly. To do make sure they are, please check the ToolsForms Options form security options.

This is a great demonstration how you can combine several Microsoft products to create excellent customer-specific solutions utilizing the out of the box features and capabilities, with no need for any extras!

For more helpful tips and "how to" guidelines feel free to visit the KWizCom blog.

KWizCom MVP Licenses