Consume User Profile Service in InfoPath

If you were trying to consume user profile service in InfoPath and you were able to query it correctly in the preview mode of InfoPath , but you were getting error while querying it after you published it to SharePoint.

Please follow these steps to impersonate the appropriate permissions while querying the service.

 

1- Create Secure Store Service Application

• Go to central Administration
-> Application Management -> Manage Service Application

• Click New Secure Store Service
-> provide the appropriate names

• After the Secure store service
got created , click on it , Generate a New Key and Enter the appropriate
password.

• Click New Enter the Target
Application ID , display name and Contact Email

• Choose in the target
Application Type = Group

• u can click next on the page identifying
the fields in the ID, leave the defaults.

• For the target application
Administrators choose Farm account.

• For the Members, add Domain
Users as the members. This will allow all users to be able to use the form and
connect to the User Profile Service. Click OK when completed.

• Once you have the Application
ID created, click the key and from the drop down menu set the credentials ,
type the farm account credentials.

 

2- Allow User from templates to
use authentication information

• Go to General Application
Settings>Configure InfoPath Forms Services in Central Administration.

• Ensure that the checkbox next
to “Allow user from templates to use authentication information contained in
data connection files” is checked.

 

3- Create a new Data Connection
Library

• Navigate to the SharePoint
portal

• Click on Site Contents ->
Add an app and create a new data connection library

 

4- Convert Data connection File

• Open InfoPath file

• Click on Manage Data
Connections

• Choose the user profile data
connection and click on convert to Connection File

• Go the data connection library
and save your connection.

 

5- Modify the connection file

• Go the data connection library

• Download the newly created
data connection file

• Open it using notepad

• To connect with our web
service, Delete the comment dashes and exclamation points from the node in the
XML and enter the app ID you have created and the credential type of NTLM. It
should look like this Where the     InfoPathID is the key
you created in the secure store

• Upload the modified file to
the data connection library.

 

6- Get the logged-in User Data

• Open InfoPath file

• Create a new Field “Username”

• Add the following formula to
the Field “translate(substring-after(userName(), "|"),
"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
"abcdefghijklmnopqrstuvwxyz")”

• In the query button Add first
the following action Set “AccountName” from the QueryFields Group = the new
Field “Username”

• Add a new Action Query
UserProfileService

• Add your own Action where
value=AccountName