** This works on InfoPath 2007as well as InfoPath Forms Services. **
-
Open your form in design mode then go to Tools > Data Connections. The Data Connection window will open click 'Add...' to add a new data connection to the form.

- This brings up the Data Connection Wizard. We want to receive data from the WebService about the current user, so choose Receive data' and click Next.

- Our data source is a WebService so choose 'Web Service' and click Next.

- Now you will have to point the wizard to the WebService. So type the location of the web service. The WebService is located in the following location http://litwareinc.com/_vti_bin/UserProfileService.asmx, Replace litwareinc.com with your Intranet or extranet URL, and click Next.

-
Here you get a list of all the methods for this WebService, choose GetUserProfileByName and click Next.

- In this screen you can specify what parameters are sent to the method, we are relying on the method's ability to return the current user name if no value is passed to it, so we will leave this as is (no value is passed to the method) and click Next.

- Next you will get the following window, just click Next.

- Make sure 'Automatically retrieve data when form is opened' is checked and then click Finish.

The GetProfileByName method returns a PropertyData array. You can think of it as a repeating table of name and value pairs.
So Now that you have a data connection that can get the current users information, you can use its values.
In the example below I will show you how to get the user's first name in a textbox.
- Add a textbox to the form.
- Go to the textbox properties by double click it.
- In the 'Default Value' section, click the 'fx' button next to the 'Value' field. This opens up the formula builder dialog.

-
Click Insert Field or Group button

- In the data sources drop down, choose the GetUserProfileByName data source.

- Expand all groups under the 'dataFields' group, and choose the 'value' field. Don't click OK yet! With data 'value' field selected, click the Filter Data, button.

- The Filter Data window will come up click Add.

- In the first drop down (value) select the Select a field or group.

9. The Select a Field or Group window will open choose the 'Name' field under the 'PropertyData' group.

-
Leave the middle drop down as is ('is equal to') and in the last drop down choose 'type text.

- This is the part where you specify which property you want returned. As we said the method returns multiple properties about the user. We want to get the user's first name, so type 'FirstName' (this is case sensitive!).
I have included a list of the properties you can use (just below), so if you want some other property, just type its name instead.

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