How to automatically retrieve current UserName in an InfoPath SharePoint list form
(SharePoint Enterprise Edition ONLY)
By using the SOAP web service there are many user properties that we can retrieve and automatically populate onto fields in the SharePoint list form.
There is a built in InfoPath field property called userName() which can be used to return the user id/ account id. To get other details such as display name, email id, manager, phone number, etc., we can use the web service “UserProfileService.asmx”
I am going to show how to retrieve the current username but in a user friendly format to a filed on your form.
First ensure you have created a text field in your list to hold the username property then select the customize form button on the ribbon as shown below (this option is only available if you are using SharePoint Enterprise edition and have enterprise licenses)
Create a New Data Connection
thenSoap Web Service Option and enter the url for your web service in this format:
Step 2 - Select the method GetUserProfileByName.
Click next thennext and finish the wizard with the checkbox for “Automatically retrieve data when form is opened” checked.
Your new data connection is now created.
Set the Your UserName Field to Use the UserNamepropoerty
In your form, goto the properties of your name textbox. In the ‘Default Value’ part, click the ‘fx‘ button next to the ‘Value’ field.
Click Insert Field or Group
Select the advanced view at the bottom of the screen then ensure you are on the GetUserProfilebyName field in the drop down at the top. Select GetUserProfileByName data source.
Keep expanding the groups under the ‘dataFields‘ group, and choose the ‘value‘ field.
Select “Filter Data” button after selecting value, and click “Add“. Filter screen appears with three dropdowns. In the first dropdown, select “Select a field or group…” and select ‘Name‘ field under the ‘PropertyData’ group.
Let the second drop down be unchanged (is equal to).
In the third drop down, select “Type Text…” and write “PreferredName".
This third drop down will decide what property is to appear in your textbox. Alternatively to return the users emailaddress , repeat all above steps with this last dropdown being set to “WorkEmail“. For account id, repeat all above steps with this last dropdown being set to “AccountName“.
Close all open dialog boxes by clicking ok.
Preview to see the output.
Below is a list of other properties that can be returned by the userprofileservice:
Did this article help you today?
If you want to know learn more about SharePoint or how it can be used to help your business book onto one of our SharePoint courses.