다음을 통해 공유


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

This method also use for get User Profile Information such as First Name , Last Name , Office and etc.

In generally we can not set a default value to InfoPath Person/Group Picker. On the other hand we can not 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).

http://lh5.ggpht.com/-qonNpEBASus/TykS-NhnhPI/AAAAAAAAAw0/lT24bTlDwh0/image_thumb2.png?imgmax=800

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.

http://lh3.ggpht.com/-FsaLbC2MnGo/TykS_zoyhBI/AAAAAAAAAxA/biqzxmAcOu8/image_thumb7.png?imgmax=800

    • 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 is depends on your site or site collection. if it is a site collection you can omit /sites/site/ part from your URL.

http://lh4.ggpht.com/-nnOFEcytZcY/TykTCL7eg9I/AAAAAAAAAxU/O0rYXX6bE7c/image_thumb12.png?imgmax=800

then proceed to next , select UserProfileByName and **un select the Automatically load.**Now you have created the connection.

http://lh6.ggpht.com/-luGkKb2r6Bw/TykTD94JiCI/AAAAAAAAAxk/iRupLKxG_bc/image_thumb14.png?imgmax=800

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

http://lh4.ggpht.com/-fvqf8EnN0zI/TykTFyk3zeI/AAAAAAAAAx0/zqZA5JgTOO8/image_thumb16.png?imgmax=800

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

http://lh5.ggpht.com/-2cE9nK2VCVg/TykTHlmFIBI/AAAAAAAAAyE/XnJBhHAwbR8/image_thumb18.png?imgmax=800

  • Then Go to the Form Load Rules.

Note : – If we Query the data source  with out 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.

http://lh3.ggpht.com/-fQwRRjWklTQ/TzzynIhugjI/AAAAAAAAAyw/PfvufndADh0/image_thumb%25255B9%25255D.png?imgmax=800

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

http://lh3.ggpht.com/-862HETSmhyc/TzzypAOOKXI/AAAAAAAAAzA/xOsVl3uoJKo/image_thumb%25255B11%25255D.png?imgmax=800

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 Valuein the form load and Click the DisplayName in the date picker control field in the Main Data Connection. You can follow below steps to do that.

 

http://lh3.ggpht.com/-IsSa-mk3bYM/Tzzyr0P7eVI/AAAAAAAAAzQ/OJs6VCrs40Y/image_thumb%25255B8%25255D.png?imgmax=800

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.

http://lh4.ggpht.com/-8PP_Dn6cDos/TzzyvIl_ZNI/AAAAAAAAAzg/Y8FVRk9AJvw/image_thumb%25255B18%25255D.png?imgmax=800

User profile data coming as key value pairs. Ex:-

  • 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.

http://lh3.ggpht.com/-9gbYwLdQ8gI/Tzzyx7bPBjI/AAAAAAAAAzw/04XGzzmE7x4/image_thumb%25255B28%25255D.png?imgmax=800

after that click Ok. After several Clicks you can see below dialog.

http://lh4.ggpht.com/-8l6ijwy4nKQ/Tzzy0NWTw0I/AAAAAAAAA0A/wH0C6-ocgAQ/image_thumb%25255B37%25255D.png?imgmax=800

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

http://lh6.ggpht.com/-9ciftKUUxJU/Tzzy17C64CI/AAAAAAAAA0M/s5p-i5w4_Uo/image_thumb%25255B39%25255D.png?imgmax=800

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

http://lh6.ggpht.com/-ter7OgCuFec/Tzzy4IqdhoI/AAAAAAAAA0g/2hkSZKins1M/image_thumb%25255B45%25255D.png?imgmax=800

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

http://lh4.ggpht.com/-Hueuu4Bz_P4/Tzzy6_Q8dOI/AAAAAAAAA0w/3g7EJSzAjHk/image_thumb%25255B54%25255D.png?imgmax=800

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

http://lh5.ggpht.com/-Tn4PHwbSgxg/Tzzy9LRoHzI/AAAAAAAAA1A/w3x5--ReYI4/image_thumb%25255B55%25255D.png?imgmax=800

Now if you preview the form you can see values coming. You can also use following name parameters to load other user profile data (FirstName, LastName) to controls (Ex- 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