Using SharePoint’s GetUserProfileByName web service to retrieve AD account information

Okay, let’s get started.  We need the user’s active directory domain and username.  Thankfully SharePoint provides us with the getUserProfile service which will easily give us what we need.  Just remember that this web service provides only the information that was imported into the user’s SharePoint profile, and so may not necessarily be up to date with the latest and greatest information, nor does it store ALL of the user’s active directory data.

  1. Create a data connection to Receive Data from a Web Service
  2. For the location, enter http://[SHAREPOINT_SERVERNAME]/_vti_bin/UserProfileService.asmx?WSDL
  3. Choose the operation: GetUserProfileByName
  4. Click Next (no need to set a default value)
  5. Click Next (no need to store the data in the form template)
  6. On the final screen, make sure to check the Automatically retrieve data when form is opened box.

Now you have a data source which provides a lot of AD information about the current user. Now you need to create a field to store this domain name in.  I added a field to myFields called UserDomainName, and set it’s default value to be the “AccoutName” returned by the web service.

  1. Right click on myFields (in the Data Source panel), click on Add, then choose UserDomainName as the Name, and leave everything else as default.
  2. Double-click on the newly created field then click on the function button (Fx) next to the Value text box (in the Default value section). 
  3. Click on Insert Field or Group
  4. Choose the GetUserProfileByName data Source
  5. Drill down through dataFields until you get to the Value field
  6. Choose the Value field
  7. Click Add (a filter)
  8. Choose Select a Field or Group…
  9.  Choose the Name field
  10. Choose the Name field
  11. Click OK.
  12. Then choose Is Equal To, and type in AccountName
  13. Keep clicking OK until you’re free
  14. Your formula should look like this.
  15. Alternatively, you could click on Edit XPath and paste in:

xdXDocument:GetDOM(“GetUserProfileByName”)/dfs:myFields/dfs:dataFields/s0:GetUserProfileByNameResponse/s0:GetUserProfileByNameResult/s0:PropertyData/s0:Values/s0:ValueData/s0:Value[../../../s0:Name = “AccountName”]

Now this field will be automatically populated with the current user’s AccountName as saved in their SharePoint user profile.  You can repeat the process to retrieve other user information, by replacing the filter for AccountName with any of the following:

UserProfile_GUID
AccountName
FirstName
LastName
PreferredName
WorkPhone
Office
Department
Title
Manager
AboutMe
PersonalSpace
PictureURL
UserName
QuickLinks
WebSite
PublicSiteRedirect
SPS-Dotted-line
SPS-Peers
SPS-Responsibility
SPS-Skills
SPS-PastProjects
SPS-Interests
SPS-School
SPS-SipAddress
SPS-Birthday
SPS-MySiteUpgrade
SPS-DontSuggestList
SPS-ProxyAddresses
SPS-HireDate
SPS-LastColleagueAdded
SPS-OWAUrl
SPS-ResourceAccountName
SPS-MasterAccountName
Assistant
WorkEmail
CellPhone
Fax
HomePhone

Full credit goes to Itay Shakury for this list, and you can read his blog post about it here.

Leave a Reply