InfoPath is a common tool used to create forms hosted on SharePoint. Due to the limited development options available for Office 365, I think this places an increased focus on InfoPath when it comes to creating a solution. Unfortunately, I found that it was relatively difficult to get the current user’s information to be displayed or saved within an Infopath form.
Typically, within the form you would just make a web service call to the UserProfileService.asmx in order to retrieve the current user. Unfortunately, I was unable to get this working when the form was deployed to an Office 365 site.  This KB article suggests this is because the Office 365 servers have loopback protection enabled.
My solution involves the following:
- Office 365 SharePoint 2013 site
- InfoPath 2013 Form with one parameter made available to use in a web part connection
- InfoPath Form Web Part
- Script Editor Web Part
- Query String (URL) Filter Web Part
Step 1: Create your InfoPath form (or cheat and download the one I’ve created User Information Infopath form). I created textboxes for each of the User fields as well as one additional one that will be used to pass information into the form.I created rules on the txtUrlParameter field to populate my other fields. This is because the InfoPath form web part can only accept one web part connection at a time so we have to cram all our parameters into one URL parameter. I decided to use a format like:
This allows me to keep my rules relatively simple inside the InfoPath form:
Step 2: Publish the form to your Office 365 site. I created a new Forms library for testing. Make sure the Url Parameter field available to use in a web part connection.
Step 3: I edited my web part page and added on my three web parts:
- Forms -> InfoPath Form Web Part
- Media and Content -> Query String (URL) Filter Web Part
- Filters -> Script Editor Web Part
Note: The “Current User Filter” web part might catch your eye. Unfortunately, this web part passes a user in the format: i:firstname.lastname@example.org. Not what we need inside an InfoPath form.
Step 4: Configure the InfoPath Form Web Part to point to the form you published in step 2.
Step 5: Configure the Query String (URL) Filter Web Part to use a URL Parameter called “userinfo”.
Step 6: Connect it to the InfoPath Form Web Part so that the userinfo parameter will populate the Url Parameter field in your InfoPath form.
Step 7: Add the following script inside your Script Editor Web Part (modified the code I found http://sharepoint.stackexchange.com/a/73037/2070). The script looks up the current user using SharePoint’s Client Object Model and creates a dynamic link. You would put the Script editor web part on another page (but for demo purposes, it works fine on the same page too). You will want to modify the HREF of the link to point the page you want.
Here is the completed InfoPath web part with pre-populated data from the current user!
Download the InfoPath form I’ve created: UserInformation.zip.