Office365 and InfoPath – GetUserProfileByName is not available – a solution

Whilst working on client project recently that involved InfoPath within Office365 I immediately wanted to use a commonly employed technique with previous projects – using the GetUserProfileByName web-service to obtain the users first and last name.

There are a number benefits to doing this, especially when the project inevitably involves workflow, custom library views, webparts etc to have a personalized experience for the user. For this specific project we needed to get the user of the form within the document as they were to form official standalone documents (as in out of the SharePoint document library context).

Unfortunately there is a BIG limitation…

“This issue occurs because loopback protection is enabled in the SharePoint Online environment. Loopback protection must be disabled for InfoPath forms to be able to connect to a SharePoint Online web service.

Any time that you make a call to the same server from an InfoPath form, the requests to loop back. This works only when loopback protection is disabled. For security reasons, loopback protection is always enabled in SharePoint Online. This is a known limitation of InfoPath forms in the Office 365 SharePoint Online environment, and there is no workaround for this issue.
Here is the article for your reference:

So we need another way to get the user data from within Office 365 and into the InfoPath form and I devised the following solution:

The overview is as follows

  • an InfoPath webpart
  • a query string filter connected to the InfoPath webpart
  • a javascript file to add the query string parameter

Now I had to provision a page with the Infopath webpart and a few other connected webparts

I then needed to get the InfoPath form to react to a query string filter webpart

Passing Parameters to Infopath – By Tomasz Szulczewski

Next I added some JavaScript via a script editor webpart to read the current user name from the user profile service view CSOM

I used some of the script from Kit Menke’s blog here

I simplified his script to just read the current user via “get_title()” and then pass this to the “window. location”

This redirects to a url with a query string parameter “CurrentUser” with this value


making sure to redirect only if the string “CurrentUser” is missing from the url. See the “check” statement…

function CustomExecuteFunction() {
var self = this;
self.context = new SP.ClientContext.get_current();
self.web = context.get_web();
self.currentUser = web.get_currentUser();
self.asyncSuccess = function(sender, args) {
var user = this.currentUser;
console.log('asyncSuccess', user);
loc = window.location.href;
check = loc.indexOf('CurrentUser');
if(check <0)
// if not the redirect with appended query string
window.location= loc + "?CurrentUser=" + user.get_title();
self.asyncFailure = function(sender, args) {
alert('Request failed. \nError: ' + args.get_message() + '\nStackTrace: ' + args.get_stackTrace());
// actually fires off the AJAX request
// more info:

So I now had the current user in the url and the query string filter webpart reading the value and passing this to the InfoPath form field – I then had a people picker field read this value and bingo I could interact as if the original query was there.

Hope this helps someone else.



3 thoughts on “Office365 and InfoPath – GetUserProfileByName is not available – a solution

  1. Hi Ryan

    you mention that you interact as if the original query was there, does that mean being able look up Office and Department etc from their name?



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.