Fun with the UserProfileService web service in InfoPath, part two

Part Two: Using the UserProfileService to Auto-Fill Fields

Today we will be using the UserProfileService to automatically populate the following fields based off the current logged user:

  • My Name
  • My Email
  • My Title
  • My Department
  • My Manager
  • My Manager’s Email
  • My Manager’s Title

If you haven’t already connected to the webservice, follow the instructions in Part One: Connecting to the UserProfileService web service in InfoPath

Once you are connected to the service, create a new InfoPath form and add the fields listed above. Your Form should look something like this:

Double-click the My Name field. Select Control Properties from the Properties tab in the ribbon. Under Default Value, click the fx button:

Click Insert Field or Group:

The Select a Field or Group dialog will display. Select GetUserProfileByName from the Fields dropdown:

Expand out the dataFields node until you get to Value. Select Value and then click Filter Data:

Click Add on the Filter Data dialog:

Under the Value dropdown, select Select a Field or group. Select Name from the Select a Field or Group dialog. Click OK:

In the third dropdown in the Specify Filter Conditions dialog, select type text and then type in PreferredName:

Click OK and then click OK on all the open dialogs. You will then follow these same steps on each of the following fields; substitute the listed text for the PreferredName text:

  • My Email: enter text Email
  • My Title: enter text Title
  • My Department: enter text Department

You should now have all of the My Info fields created and have default values added for each. For the manager’s section, we will add a new data connection using the UserProfileService, except when you get to the Operations screen, instead of selecting GetUserProfileByName you will select GetCommonManager:

Once the new data connection for GetCommonManager is made, select the control properties for the My Manager field, click the fx button, click Insert Field or Group. In the Fields dropdown that displays on the Select a Field or Group dialog, instead of selecting GetUserProfileByName, select GetCommonManager. Expand out the GetCommonManagersResult node and then select Name. Click OK on all open dialogs:

Follow these steps on each of the remaining Manager fields with the following substitutions in the Select a Field or Group > GetCommonManagerResult node:

  • My Manager’s Email: select Email
  • My Manager’s Title: select Title

Save your file and preview. your result should look like this:

Stay tuned for Part Three: Using the GetCommonManager function to display a user’s supervisor hierarchy.

Advertisements

13 thoughts on “Fun with the UserProfileService web service in InfoPath, part two

  1. Pingback: Fun with the UserProfileService web service in InfoPath, part two …

    • Sure. The example I created was set up to show up to five levels of hierarchy. You need to create a new data connection for each level you want to pull back (Mgr1, Mgr2, etc.)

  2. This was wonderful help! Thank you. I cant wait for part three. I want to show 2 levels but am stuck. I get the first one just fine but my brain doesn’t see how to go one step down. Can you expand on your last comment on now to setup the data connections for each level?

    Thanks again!

  3. Man you saved my day. Thank you very much. When is part 3 coming out?

    You said:

    The example I created was set up to show up to five levels of hierarchy. You need to create a new data connection for each level you want to pull back (Mgr1, Mgr2, etc.)

    How did you do that?

    Thanks in advanced

  4. I have tried the above example but not able to populate the Title and Department fields. I’m using InfoPath 2007 and SharePoint 2010 and not sure why this won’t work any ideas? The default properties on the MS website say that JobTitle is SPS-JobTitle but I’ve tried with Title, JobTitle and SPS-JobTitle and still no joy. Any ideas?

  5. Hi: It worked wonderful. however when I added another List Connection to the form – an error turned everything sour. Message “Error occurred querying a data source, click ok to resume filling out the form. you may want to check your form data for errors .. You don’t have permission to access Webservices that provides data required for tis form to function correctly. Entry has been added to the Windows Event log file of the server Lod Id 5566

    • In addition, I’ve now managed to get manager’s name to appear but not the name. I am able to get the guid of the user logged in i.e. me if I select a different field to show on the form. Perhaps the function of converting to preferred name is different in SharePoint Online?

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