Recently I needed to get the current user and their manager’s Active Directory profile to auto-populate a form. Itay Shakury wrote a great blog post titled Get the current user without writing code that covers the first need (current user) by reading UserProfileService.asmx. But I needed more.
Download sample form – ADManagerDetails.xsn
The strategy was to use 2 data connections and query the 2nd with the manager user ID from the first. At that point you can map any document text field to be ready only and get the default value from one of these data connections.
- New InfoPath form in design mode
- Add 2 receive data connections to http://sharepoint2007/_vti_bin/UserProfileService.asmx
- Name them “UserProfile” and “ManagerProfile”
- Leave the input parameters empty. It will default to the current user.
- Open form Rules and add steps to “re-query” the ManagerProfile:
- Set field’s value: query subtree of ManagerProfile to “Manager” value from UserProfile data tree
- Query data connection ManagerProfile. With the filter set, it will now return different data.
- Enjoy and tell your friends.
Video Walkthrough (05:57)
How to build the sample form (above download) in full step-by-step video. Only 6 minutes! Well worth the time.