Saturday 30 May 2009

Display login user name on InfoPath form automatically

The GetProfileByName method returns a PropertyData array. You can think of it as a repeating table of name and value pairs.
So Now that you have a data connection that can get the current users, you can use it values. In this example I will show the user's first name in a textbox.

1. Add a textbox to the form.

2. Go to the first textbox's properties (double click it).

3. In the 'Default Value' part, click the 'fx' button next to the 'Value' field. this opens up the formula builder dialog.



4. Click 'Insert field or group'.


5. In the data sources drop down, choose the GetUserProfileByName data source.
6. Expand all groups under the 'dataFields' group, and choose the 'value' field. Don't click OK yet!
7. With data 'value' field selected, click the 'Filter Data...' button and 'Add...'.
8. In the first drop down (value) select 'Select a field or group...' and choose the 'Name' field under the 'PropertyData' group.




9. Leave the middle drop down as is ('is equal to') and in the last drop down choose 'type a text...'.


10. This is the part where you specify which property to put in the textbox. As we said the method returns multiple properties about the user. For this textbox we want to put the user's first name in, so type 'FirstName' (this is case sensitive!). I have included the property list you can use here (just below), so if you want some other property, just type its name instead.

11. That's it, all we have to do is to confirm everything so Click 'OK' for every open dialog box until you are back in the design mode.

12. click 'Preview' and see the wonder!

13. If you want more details repeat steps 1-11 and enter different property names in step 10.
Finally, as I Promised, here is the complete list of default profile properties get returned by the userprofileservice.


I think they are pretty self explained:

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

6 comments:

  1. Hi,
    May I know how to call out GetUserProfileByName data source?

    Currently, only got Main data source in the drop down.

    Appreciated if you could guide me.

    Thanks in advance.

    Regards
    Cindy Tan

    ReplyDelete
  2. This is not well explained at all. Please do not post information that is not complete or accurate. Thanks!

    ReplyDelete
  3. http://melick-rajee.blogspot.com/2012/02/how-to-set-current-user-name-to.html
    http://blogs.microsoft.co.il/blogs/itaysk/archive/2007/04/05/InfoPath-_2D00_-Get-the-current-user-without-writing-code.aspx?from=ClayCobb

    ReplyDelete
  4. Some external data was not retrieved. The form will load without the requested data.

    ReplyDelete
  5. you must have left out a lot steps, I do not have a GetUserProfileByName. and it looks like nobody else does either.

    ReplyDelete