Click here to Skip to main content
15,615,155 members
Articles / Operating Systems / Windows
Technical Blog
Posted 17 Feb 2012

Tagged as


3 bookmarked

How to set Current User Name to InfoPath Person/Group Picker

Rate me:
Please Sign up or sign in to vote.
5.00/5 (4 votes)
17 Feb 2012CPOL3 min read
How to set Current User Name to InfoPath Person/Group Picker

This method is also used for getting User Profile Information such as First Name, Last Name, Office, etc.

Generally, we cannot set a default value to InfoPath Person/Group Picker. On the other hand, we cannot get Current Username in the InfoPath. (Yeh, it is true that we can use userName() function. But this will return the Current User Account ID, not the name).


So we want to use SharePoint user profile services to do this.

  • First, we need to create a user profile connection.
    • Thus first go to manage connection and click add connection.


  • Then go to receive data option and SOAP Web service and specify the User Profile Service URL. The URL will be something like (http://sever/sites/site/_vti_bin/UserProfileService.asmx). This depends on your site or site collection. If it is a site collection, you can omit /sites/site/ part from your URL.


    Then proceed to next, select UserProfileByName and unselect the Automatically load. Now you have created the connection.


  • Now you have User Profile connection to receive profile data.


  • For an example, we will design a form like below. You need to set the current user automatically when the form loads.


  • Then go to the Form Load Rules.

    Note: If we Query the data source without parsing any parameters, it will load the current user detail.

  • Thus now we are going to query the data connection (GetUserProfileByName) in the form load. thus Go to Form Load rules and then set a Action as Query for data and select the UserProfile Data Connection.


Then click Ok. Now you have configured the data connection. Now you have Form Load rule for query user profile service.


For InfoPath person picker to identify the user, we need to set DisplayName as well as AccountID.

Now we are going to set the display name for the control. So Add a new Action Set a Field’s Value in the form load and Click the DisplayName in the date picker control field in the Main Data Connection. You can follow the below steps to do that:


Then we need to assign the value for displayname. Thus we need to get that value form the data connection “GetUserProfileByName” that we already queried in the form load. Thus now it contains user profile data for the current user. Only we need to fetch the value related to Display name.


User profile data comes as key value pairs. Example:

  • value[“PreferredName”] = Some Name
  • value[“AccountName”] = Some Value
  • value[“FirstName”] = Some Name

Thus we need to pick the correct data from the Value. Thus we need a filter Display Name from the Value.


After that, click Ok. After several clicks, you can see the below dialog:


Now you have two actions (one for query and other for Set PreferredName to DisplayName field in the person/group picker control):


Now you are done with setting the DisplayName of the Person/Group Picker Control. Then we need to assign the AccountID, so go to the very first step. and then add a new action to assign the value for AccountID. So select the AccountID (Very first step, we selected DisplayName earlier):


Then proceed with the same method and finally give filter as AccountName, which we assigned PreferredName earlier.


Now you have three actions in the Form Load and now you are done.


Now if you preview the form, you can see values coming. You can also use the following name parameters to load other user profile data (FirstName, LastName) to controls (Example - TextField, Combo) as well.

  • UserProfile_GUID
  • AccountName
  • FirstName
  • LastName
  • PreferredName
  • WorkPhone
  • Office
  • Department
  • Title
  • Manager
  • AboutMe
  • PersonalSpace
  • PictureURL
  • UserName
  • QuickLinks
  • WebSite
  • PublicSiteRedirect
  • SPS-Dotted-line
  • SPS-Peers
  • SPS-Responsibility
  • SPS-Skills
  • SPS-PastProjects
  • SPS-Interests
  • SPS-School
  • SPS-SipAddress
  • SPS-Birthday
  • SPS-MySiteUpgrade
  • SPS-DontSuggestList
  • SPS-ProxyAddresses
  • SPS-HireDate
  • SPS-LastColleagueAdded
  • SPS-OWAUrl
  • SPS-ResourceAccountName
  • SPS-MasterAccountName
  • Assistant
  • WorkEmail
  • CellPhone
  • Fax
  • HomePhone


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Sri Lanka Sri Lanka
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

Questionworking in preview not working in browser Pin
Member 1412961825-Jan-19 0:17
Member 1412961825-Jan-19 0:17 
QuestionAboutMe Field Pin
Lionheart8314-Nov-14 3:31
Lionheart8314-Nov-14 3:31 
QuestionThanks you. It worked.. Pin
umakant_uma11-Sep-14 7:06
umakant_uma11-Sep-14 7:06 
QuestionUserName in NewForm InfoPath Pin
cdix4-Sep-13 4:20
cdix4-Sep-13 4:20 
Questionquery userprofile best practice Pin
Guy Perry13-Aug-13 10:46
Guy Perry13-Aug-13 10:46 
Questionproblem was Pin
prageeth.madhu19-Jun-12 3:45
prageeth.madhu19-Jun-12 3:45 
AnswerRe: problem was Pin
Member 256541221-Jan-13 6:30
Member 256541221-Jan-13 6:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.