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
- 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.
- 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:
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.
the solution to this error is headache a bit,for a good diagnostic try the below solutions one by one:
- Made sure all the data connection files have the environment specific List GUIDs, URLs and so on
- 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
- Made sure all the relevant user profiles are properly imported under SSP
- 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:
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.