How to automatically retrieve current UserName in an InfoPath SharePoint list form

Jul 14, 2014 - by Andrew Reeves

(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:

http://yourhostsitename/yoursite/_vti_bin/UserProfileService.asmx

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:

AccountName
FirstName
LastName
PreferredName
WorkPhone
Office
Department
Title
Manager
AboutMe
PictureURL
UserName
Assistant
WorkEmail
CellPhone
Fax
HomePhone

If you would like to know learn more about SharePoint or how it can be used to help your business book onto one of our SharePoint courses.

If this article helped you, please tweet, like or +1 using the buttons below - thanks!

20 comments

  1. Jason Lehr

    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.

  2. AndrewReeves

    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.

  3. Bijay Acharya

    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.

  4. Walter Reynolds

    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"

  5. indu

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

  6. Sasha

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

  7. DDS

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

  8. indu

    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

  9. Jason Firth, Mi...

    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.

  10. Sheila Smith

    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.

  11. Afrah

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

  12. Shawn Harris

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

  13. MS

    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.

  14. Els Croux

    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...

  15. Manjit

    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

  16. Sudhir

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

  17. Maja

    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

  18. Wandi

    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 :-)

  19. Carlos

    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.

  20. Ryan

    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!

Leave a reply