Querying SharePoint Profile Data from an InfoPath Form

    Problem

    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.

    Solution

    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

    clip_image001

    Create a new data connection

    clip_image002

    Choose Web Service

    clip_image003

    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)

    clip_image004

    Choose the GetUserProfileByName operation

    clip_image005

    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.

    clip_image006

    Do not store a copy of the data in the form template

    clip_image007

    You can rename the operation here but I recommend leaving it exactly as is

    clip_image008

    Now note the data connection in the data source view

    clip_image009

    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.

    clip_image010

    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)

    clip_image011

    Under User Profiles and My Sites select “Personal Services Permissions” and grant your users, such as domain\domain users, rights to read user profiles

    clip_image012

    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)

    clip_image013

    Create a rule on the AccountID field called GetEmployeeProfile

    clip_image014

    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

    clip_image015

    The next action in the rule should query the GetUserProfileByName data connection

    clip_image016

    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)

    clip_image017

    Our filter condition will appear as follows

    clip_image018

    After selecting OK our filter data now appears under existing filters

    clip_image019

    Click ok again and you can see that we are asking the profile datasource for the ValueData.Value where the PropertyData.Name equals “Department”

    clip_image020

    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

    clip_image021

    The resulting rule will appear as follows

    clip_image022

    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.

VN:F [1.9.1_1087]
Rating: 8.6/10 (5 votes cast)
VN:F [1.9.1_1087]
Rating: +2 (from 2 votes)
Querying SharePoint Profile Data from an InfoPath Form, 8.6 out of 10 based on 5 ratings

Popularity: 20% [?]

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
Share this Post:
Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

2 Responses to “Querying SharePoint Profile Data from an InfoPath Form”

  • Gavin says:

    Any idea why the rule is not being fired on either the AccountID or the People group?

    VA:F [1.9.1_1087]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.1_1087]
    Rating: 0 (from 0 votes)
    • GEM says:

      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

      VA:F [1.9.1_1087]
      Rating: 0.0/5 (0 votes cast)
      VA:F [1.9.1_1087]
      Rating: 0 (from 0 votes)
  • Leave a Reply:

    Name (required):
    Mail (will not be published) (required):
    Website:
    Comment (required):
    XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>