Auto filling InfoPath forms with current SharePoint user info without code – using web service

One of the most required issues, is retrieving current user info within a form request, either this request is normal SharePoint list form item or even InfoPath form, one may say why each time filling my personal data in such request?!.

Today i have a good solution using InfoPath forms, and its feature of data connectivity with web service, so let’s start

  1. Open a new InfoPath form even blank solution or SharePoint list, or form list, then drop your controls which may be a simple textbox to retrieve the current user name and another one for example for e-mail address.
  2. Open the data ribbon and choose From Web Service like below

and select from SOAP web service

3.  it will ask you for providing the web service url for example type :http://%5BServer name]/_vti_bin/userprofileservice.asmx?WSDL 

while [server name] is your SharePoint host server

4. after doing its connection to the web service, you will see a dozen of web service in a  list like below, choose (GetUserProfileByName) and click next

5. go to your textbox and double click its field property in the ‘Default Value’ part, click the ‘fx’ button next to the ‘Value’ field. this opens up the formula builder dialog like below and click insert field or group button, from the Fileds drop down list select our data connection

6. Expand all groups under the ‘dataFields’ group, and choose the ‘value’ field. Don’t click OK yet! just click filter data and then click add..

7. In the first drop down (value) select ‘Select a field or group…’ and choose the ‘Name’ field under the ‘PropertyData’ group.

8. Leave the middle drop down as is (‘is equal to’) and in the last drop down choose ‘type a text…’. and type carefully (FirstName) it’s case sensitive, i’ll bring a list of properites which you can use to retrieve user data at the end of this topic.

9. finally your formula will look like that ;

10. Now test your form by publishing it to SharePoint form list or even by previewing it you will retrieve your current user first name, but be sure that in user profile service this user have a first name property .

Here you are the list of properties:

  • AboutMe
  • AccountName
  • Assistant
  • CellPhone
  • Department
  • Fax
  • FirstName
  • HomePhone
  • LastName
  • Manager
  • Office
  • PersonalSpace
  • PictureURL
  • PreferredName
  • PublicSiteRedirect
  • QuickLinks
  • SPS-Birthday
  • SPS-DontSuggestList
  • SPS-Dotted-line
  • SPS-HireDate
  • SPS-Interests
  • SPS-LastColleagueAdded
  • SPS-MasterAccountName
  • SPS-MySiteUpgrade
  • SPS-OWAUrl
  • SPS-PastProjects
  • SPS-Peers
  • SPS-ProxyAddresses
  • SPS-ResourceAccountName
  • SPS-Responsibility
  • SPS-School
  • SPS-SipAddress
  • SPS-Skills
  • Title
  • UserName
  • UserProfile_GUID
  • WebSite
  • WorkEmail
  • WorkPhone

Some important notes that you may face during this scenario:

  • This scenario is applicable with both SharePoint 2007 and 2010
  • a common error you may face while publishing to SharePoint and try to insert new form this error is:

An error occurred accessing a data source.

An entry has been added to the Windows event log of the server.

Log ID:5566

the solution to this error is headache a bit,for a good diagnostic try the below solutions one by one:

  1. Made sure all the data connection files have the environment specific List GUIDs, URLs and so on
  2. Made sure all the settings related to InfoPath Forms Services under Central Admin are proper: Enable web service proxy, Enable cross-data connections, Disable Anonymous access
  3.  Made sure all the relevant user profiles are properly imported under SSP
  4.  Made sure that the authentication Loopbackcheck registry entry is disabled on the WFE server

you will do so by the following steps:

1. Click Start, click Run, type regedit, and then click OK.

2. Locate and then click the following registry subkey:

   HKEY_LOCAL_MACHINE

   –>SYSTEM

        –>CurrentControlSet

             –>Control

                  –>Lsa

3. Right-click Lsa, point to New, and then click DWORD Value.

4. Type DisableLoopbackCheck, and then press ENTER.

5. Right-click DisableLoopbackCheck, and then click Modify.

6. In the Value data box, type 1, and then click OK.

7. Exit Registry Editor.

8. Restart the computer.

5. Made sure the alternate access mappings or managed paths are not breaking the web service calls in the interim.

After trying all the above solutions your application will retrieve the web service data.

About Hossam Kamal

Hossam Kamal Senior SharePoint Developer with high development skills in C#, ASP.NET, SharePoint Server Technologies, jQuery, CSS, XML, O.O.D, SSRS and MS.SQL Server.
This entry was posted in InfoPath, SharePoint Development, SharePoint General. Bookmark the permalink.

14 Responses to Auto filling InfoPath forms with current SharePoint user info without code – using web service

  1. When I attempt to access the site, this message shows up: “403 Forbidden – You don’t have permission to access / on this server. Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.” I’ve never experienced a issue like this before; is it through some wrong doing of mine, or maybe there something wrong with the website itself?

  2. I hardly drop remarks, however i did some searching and wound up here Auto filling InfoPath forms with current SharePoint user info without code – using web service | SharePoint Hero !. And I do have some questions for you if it’s allright. Is it just me or does it seem like some of the remarks appear like they are coming from brain dead individuals? 😛 And, if you are writing on additional places, I’d like to keep up with anything fresh you have to post. Would you make a list of all of your community pages like your Facebook page, twitter feed, or linkedin profile?

  3. 統一發票 says:

    Well written write-up, please keep it up !!

  4. Mona Mulloy says:

    Good info! Waitin’ for a sequel! 🙂

  5. I really appreciate your piece of work, Great post.

  6. For what reason won’t the hyperlinks on the top bar of the site page that post a comment work for me? Appreciate it

  7. I wonder if others will be compelled to think more on this.

  8. keliyra says:

    You, my new friend, are a rockstar! Thanks for writing this, it’s exactly what I needed in a clear concise format 🙂

  9. Kaveh Hariri says:

    Thanks for taking the time. But this only fills out first name. How do we get it to show last name or department? Do we have to set up a new connection? THe connection you used only has 4 data fields, one of them is name (first name), but it doesn’t have last name or department, etc. Thanks.

  10. Vaishnovi Patel says:

    Great article!
    However I am trying to show both first and last name in the same text box… I tried to add a second constraint in the Specify Filter Conditions menu by adding FirstName and LastName as the two conditions but I didn’t get results; mind you I didn’t receive any errors either. Is there a way to get around this?
    Thanks in advance!

    • Vaishnovi Patel says:

      Found the solution! PreferredName does the trick! 🙂
      Thanks again for such a great resource!

Leave a comment