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?

Yes, thank you :)No, sadly not :(


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.


You know how I can use this to append an Attendee field in a calendar list? Trying to do so without letting the end-user change any of the existing names etc.

I would suggest that you put each name that is attending into a hidden section. Then grab their username using the above and then show only their section when they log on. Then give them a box to tick in that section to agree attendance. This way only the person can tick the box as no one else would see it.

I need to hide a Text Box based on the Logged in User access level. If the user is the creator or part of Admin group then user will see the text box or else it will be hidden. I have used GetUserprofile service to find logged in user details and then comparing with creator and Admin Group making the control hide or show accordingly. But for New form post implementation its work as expected but for existing forms its not fetching the Display Name of the logged in user. Please help me here if any one has any solution.

This works fine when previewing the form in InfoPath Designer but when I publish it I get errors. "An error occurred while trying to connect to a Web service. Correlation ID:9f80cb39-ea0d-4cc7-9de2-ba4da5146e26"

I am getting same error. Can you tell what to do?

you need set AccountName,for example get info from text field or insert id user.

I agree with Walter great on the preview but Sharepoint throws me an error 5556. :( Any ideas?

I am also getting when I publish the form in share point while using the browser. Any ideas? An error occurred while trying to connect to a Web service. Correlation ID:9f80cb39-ea0d-4cc7-9de2-ba4da5146e26

If you're getting this error when you publish to SharePoint, but not in the preview, you need to set up the secure store service and est the InfoPath stuff as an application. Then publish the data connections into SharePoint and amend them to use the secure store service.

This is exactly the issue that I am having but unsure as to how to "setup secure store severice and est the InfoPath stuff as an application, then publish the data connection into SP and amend them to use the secure store service". Is there any way you could give instructions or lead me to a link that can? Thanks.

Did you manage to resolve this issue? If yes, can you provide me the link to the steps. Thanks!

How to publish data connection to sp

I'm having the same problem as the people do we resolve this. PS I don't have access to the farm.

I tried this SharePoint Online InfoPath form, getting an error message that 'The file or folder name 'https://site/_vti_bin/UserProfileService.asmx?WSDL' contains characters that are not permitted. Enter a different name.

Perfect, Whatever I tried, I could not make it work, and then I found this Step-by-step workflow... and it did the job. If I had looked for this article sooner, it would have saved me a week of stress and ...cursing. Thank you so much, I would never have found it...

working fine..i m getting name also but the format of name is "color:red,italic" but it should be "color:black,underline" which comes in later format when i click on people picker

I found this article very useful. Though I have yet to see if it works when I publish it.

Thank your for this article. I followed the instruction and I don't received errors after i published to the SharePoint 2013 site. However the result value is wrong. the value appear is not the profile of the current logon user but instead the other profile user. And i observed after i Set the credentials , whoever the name i put on the username, that profile username appear on the form. Did i make something wrong. Please help. Thanks in advance

Thank you for the article. I followed as per instructions and it works on our teamsite. Only have 1 issue where by my next superior (Manager Name) appear as "domain\manager name" . Still a great article thou :-)

This works fine when previewing the form in InfoPath Designer but when I publish it the textfild said " SharePoint 15 Content Web App Pools " . Please help.

I followed the guide and it worked. I've been trying to find this solution for a while now and I'm glad I finally found this article. I can't believe Microsoft would not provide the option to set the user field default to the current user, but I'm glad I found this workaround. Thanks again!

This works fine when previewing the form in InfoPath Designer but when I publish it the textfild said " SharePoint 15 Content Web App Pools

Make sure when you set the user you use the substring function to cut the token info from the username. You want all the info after the | character.

I'm getting the variable name in the Preview rather than what I would expect should be my own? Everything appears to be working without error. I'm in a position where I cannot publish until I'm actually done - no developing environment except my computer. Can you specify - am I suppose to see my own name (if I'm in the SharePoint userbase/GAL) or am I supposed to see the Variable only when previewing?

How do i attach a document automatically in an infopath form when it loads? I want users to be able to see the attachment and read it before submitting the form Thanks

it works perfectly in the preview, but not in production

Hello, Thanks for your post. I am using sharepoint 2016. I followed step by step but I get this error. "An error occurred querying a data source. Click OK to resume filling out the form. You may want to check your form data for errors. " An error occurred while trying to connect to a Web service. An entry has been added to the Windows event log of the server. Log ID:5566 Please how can I solve this problem? Thank you.

I get the same error Tony gets and the name displays in preview but not in the submitted form.

All the images are blank

Add new comment