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.
- Create a data connection to Receive Data from a Web Service
- For the location, enter http://[SHAREPOINT_SERVERNAME]/_vti_bin/UserProfileService.asmx?WSDL
- Choose the operation: GetUserProfileByName
- Click Next (no need to set a default value)
- Click Next (no need to store the data in the form template)
- 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.
- Right click on myFields (in the Data Source panel), click on Add, then choose UserDomainName as the Name, and leave everything else as default.
- 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).
- Click on Insert Field or Group
- Choose the GetUserProfileByName data Source
- Drill down through dataFields until you get to the Value field
- Click Add (a filter)
- Choose Select a Field or Group…
- Choose the Name field
- Click OK.
- Then choose Is Equal To, and type in AccountName
- Keep clicking OK until you’re free
- Your formula should look like this.
- 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:
Full credit goes to Itay Shakury for this list, and you can read his blog post about it here.