An Alternative Approach To Query User Profile Service In Infopath Using SharePoint Online

Background 

In InfoPath form, to auto-populate the user details, generally, we, SharePoint Developers, use the GetUserProfileByName method by creating a data connection to

https://tahmidulabedin.me/_vti_bin/userprofileservice.asmx?WSDL . And, we used to use this in SharePoint on-premises. A few days ago, I was trying to create an InfoPath form in SharePoint Online with Office 365 and I got an error as "An error occurred while connecting to a Web Service."

After digging into the internet, I got that Microsoft have purposefully disabled access to the User Profile service to prevent Loop Back issues. As per Microsoft support, to call UserProfileService web service, the data security authentication is required before the service will return any data. And the method, GetUserProfileByName of SharePoint UserProfileService makes the call anonymously, which is the convention for all web calls. As anonymous access is not allowed in the web application, the SharePoint server returns an authentication error (code 401).

How to overcome this error

Now, I had to overcome this issue and I found one solution. To create a Data Connection for populating common user fields, using “User Information List” hidden list is the best approach. To create a data collection with this list, we need to follow the usual approach of creating a data connection in InfoPath and select SharePoint List or Library as the data source.


Fig: Selecting User Information List as Data Source

The hidden list will be shown with other SharePoint lists. And by selecting this, we will get several user attributes which can be pulled as required.

Selecting the needfull fileds from
Fig: Selecting the needful fields

That's it. If anyone knows any better approach, please let me know in the comments below and I will update my tip.

Ebook Download
View all
Learn
View all