Day after day I have users asking me how to get additional information about the selected user from the contact selector/people picker per my example at http://sharepointassist.com/2009/02/27/adding-a-contact-selectorpeople-picker-to-an-infopath-form/.
Unfortunately, there is no easy way to do this, the only way to do this is to wire in a simple web service query that pulls the necessary information when a user chooses a name in the people picker. Upon selection, the web service call is made, returning data to the GetUserProfileByName data connection, the resulting data in the GetUserProfileByName data connection can be diligently filtered and used to set the values of fields in the main data connection.
Locate the asmx file for the user profile service of your server MOSS 2007 Server: it should appear similar to this URL: http://sharepoint/_vti_bin/UserProfileService.asmx?WSDL
Open InfoPath and select Tools >> Data Connections
Create a new data connection
Choose Web Service
Enter the URL to the UserProfileService.asmx web service (hint, test this in a browser, if it doesn’t work there it certainly will not work in InfoPath)
Choose the GetUserProfileByName operation
Note the parameter, you will not need to enter a default value
** Hint: If you run the GetUserProfileByName without specifying a name, SharePoint will return the profile data for the currently logged in user.
Do not store a copy of the data in the form template
You can rename the operation here but I recommend leaving it exactly as is
Now note the data connection in the data source view
Now we are going to try creating a data connection from infopath that queries this web service, some of your users might see the warning below when testing with their personal accounts.
To grant users rights to query the profile database open “Central Administration” and select your shared services provider (take care not to accidentally expose profile data that you would not normally like to share)
Under User Profiles and My Sites select “Personal Services Permissions” and grant your users, such as domain\domain users, rights to read user profiles
Now in your people picker (see article http://sharepointassist.com/2009/02/27/adding-a-contact-selectorpeople-picker-to-an-infopath-form/) add a rule to the AccountId group that runs only when the AccountId is not blank.
** If the rule does not trigger for the AccountId field try adding it to the Person group
We are going to set the value of the queryfield in the secondary data source called GetUserProfileByName to the value of the AccountId field in our people picker’s data structure. After that we will query the GetUserProfileByName then set the Employee’s Department equal to the Value returned (note that we need to filter the PropertyData, more on that later)
Create a rule on the AccountID field called GetEmployeeProfile
Set the value of the secondary data source GetUserProfileByName to the AccountID
** Hint, the AccountId can be any field that contains the user’s username
The next action in the rule should query the GetUserProfileByName data connection
Filter the ValueData where the “Name” field equals the user profile property name such as Department (note that you could do this for Title, WorkPhone, Manager, etc. as long as that field is a property in your profile database)
Our filter condition will appear as follows
After selecting OK our filter data now appears under existing filters
Click ok again and you can see that we are asking the profile datasource for the ValueData.Value where the PropertyData.Name equals “Department”
After all that you can see that we are setting a field in the main data source to a value we located in a secondary data source called GetUserProfileByName
The resulting rule will appear as follows
Note that the query does not work across domains!!!
Hint: If you run the GetUserProfileByName without specifying a name, SharePoint will return the profile data for the currently logged in user… this is useful for pre-populating the form on open.
Querying SharePoint Profile Data from an InfoPath Form, 8.9 out of 10 based on 11 ratings
Any idea why the rule is not being fired on either the AccountID or the People group?
Hi Gavin,
Can you get another information e.g. email, department successfully by using the above method? I can’t do it successfully, is there any concern?
GEM
I’m using SP 2010. When I try to add a rule to the People Picker field, it only allows formatting rules. Do you have any instructions that would work for SP 2010?
Nevermind, finally got if figured out on 2010.
Wait, I have the same issue with 2010. How did you get it figured out?
I am trying to figure out in SP2010 too. I have a SP list which has server names and app owners’ email ids. I have a drop down list on my infopath 2010 form that has the server names from the sp list. When I pick a value from a drop down list, I want to populate a text box with the app owner’s email value. This form used to work in Infopath 2007. But in 2010, the Person type shows only DisplayName, AccountId and AccountType, noi email.
Hi,
The above examples queries the data based on the Account Id. But i want to query it based on the last/first name of the user. Is there any way of doing it?
Its very urgent!!
Thanks,
RoseMary
How would I apply this logic to retrieve multiple emails from contact selector control.
Thanks
