Getting the current user’s manager in an InfoPath form with SharePoint

This is a common request from customers. Of course, we have easy access to who the current user is via the username() function. Assuming the user’s manager is stored in Active Directory, you could write a web service that accepted the username as a parameter, and returned the manager name. Or, if you’re using MOSS and have set up profile imports, then you can use that web service from infopath.

Here’s the summary:

Set up a data connection to the MOSS userprofile web service. It takes an input parameter (the username), and returns a repeating group with all of the different available properties and values. Once the data connection is configured, add a button to trigger the data query, and then set the value of a textbox (with either a rule or just using the textbox’s default value) to be the desired value using a filter.

A little more detail:

1. In infopath, set up a new data connection to receive data from a web service. The web service url should be:

http://sharepointservername/_vti_bin/userprofileservice.asmx

2. On the “select an operation” page of the wizard, select “getuserprofilebyname”

3. Hit next and take the defaults for the rest of the wizard, but make sure to deselect the option to “automatically retrieve data when form is opened”

4. On the infopath form, add two textboxes and a button. Set the first to have a default value of username(). Before setting up the second textbox, first set up the button

5. Go to the rules for the button and set up two actions:

a. Set a fields value: Set the accountname query field that is in the secondary data source to be the value that is in the first text box (the username textbox)

b. The second action should be to query using a data connection:

The goal of this is to get the managers name into the second text box, but you may want to take a moment to see what data is available within the service. In the data source window, switch to the secondary data source in the drop down, and drill down in the data fields until you get to the PropertyData element, and drag it onto the form, and select to have a repeating table.

Run the form and click the button. In the table will be all the available fields and values. Take note of the exact spelling and case of the name of any fields you want to retrieve.

6.  Set up the default value of the second textbox:

The value should be the value field with a filter set to retrieve the row where Name = “Manager”

7. After clicking on the fx button for the default value, select “insert field or group”

8. Change the data source drop down to be the secondary data source, and drill down to the value field:

9. Then, click on filter data.

10. Add a filter.

11. In the “specify filter conditions”, click on the first drop-down and “select a field or group”.

12. Select the Name field:

13. Back in the “specify filter conditions”, in the drop down on the right, select “type text” and type in the name of the field you are trying to retrieve.

Again, the field names are case sensitive!

That’s it!

Advertisements

One thought on “Getting the current user’s manager in an InfoPath form with SharePoint

  1. Clayton Cobb

    If you’re just trying to get the current user’s manager, then you don’t need a button or field to put in the username. You should just check that box at the end of the data connection that automatically retrieves info, because it will by default send the current user’s username to the web service upon opening of the form and thus populate the Manager field if you set the Manager’s field’s default value to the statement you showed how to create.

    You would the extra username field and button for getting the Manager’s name or any other profile information about a user OTHER than the current user. Let the web service run itself if you only need the current user. I have an extended write-up of this and other methods also on WordPress:

    http://claytoncobb.wordpress.com/2009/06/21/userprofileservice-extended/

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s