1,789 articles and 14,283 comments as of Saturday, December 4th, 2010

Tuesday, November 30, 2010

InfoPath and UserProfileServices: what can be done…

Guest Author: Pascal Poeck
SharePoint AfterWork

Most of the time, when I use InfoPath forms in SharePoint, I need to capture the current user name to put it on my form. Nothing very complicated about that but this time I want to retrieve the other properties of my user that I can find in my Active Directory. The idea is to create a kind of badge that I will use on the Human Ressources page of my Intranet like this one:

As you can see, all of the fields on my form come from my User Profile, even the picture. The first thing that you need is, like always, to create a new list in SharePoint but you can also use a Form Library if you want. I’ll assume that you can do that by yourself so I will skip this step (basically you just need a custom list with one column for the name of your badge, nothing more).

Now that your list is created, you can customize it by clicking on the “Customize Form” button on the ribbon (in the “List” tab). Before you customize your form you will need to create a Data Connection in InfoPath to catch all the fields that you need. Click on the “Data Connections” button in the ribbon (under the “Data” tab) to open the Data Connections window and follow these steps:

  1. Click on “Add” to add a new data connection
  2. The connection is suppose to receive data (from your AD), so you just have to click on the “Next” button
  3. Click on “Next” to use the SOAP Web Service
  4. Enter the location of the SOAP Web Service definition which is http://servername/_vti_bin/UserProfileService.asmx
  5. Scroll down in the “Operation” window and select GetUserProfileByName. Click on “Next”
  6. We don’t need to specify what parameters are sent to the method, so just click on “Next”
  7. Click on “Next”
  8. Give a name to your Data Connection and click on ‘Finish”

Ok now we can customize the form so select the table and delete it. We will create a new table based on 3 columns and 6 rows by using the “Custom Table” button in the ribbon (under “Insert” tab).

Select the first row and merge all three fields in one. Do the same for the last row and for the first column so you have a table like this one:

  • Enter a title for your form in the first row.
  • Click inside the first cell on the second row and add a Picture object from the ribbon.
  • Click on the “Field Properties” on the ribbon under the “Control Tools” tab.
  • Click on the “Fx” button next the value field
  • Click on the “Insert Field or Group” button
  • Select the data connection created before in the Fields dropdown
  • Expand all to get the “Value” field (the last one) and click on “Filter Data”
  • Click “Add” and choose “Select a Field or Group” in the first cell
  • Click on the field “Name”
  • Set the second one to “is equal to”
  • Select “Type Text” in the third and enter the label “PictureURL” (be carefull it is case sensitive)
  • Close all the windows by clicking on “OK” everywhere.

That’s it for the picture. Do the same for the other fields that you want to have on your form. The only difference is that you have to put a “Text Box” in place of a “Picture” control and also that you must use another label than “PictureURL”. Here is the list of the default properties that you can use with the web service GetUserProfileByName:

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

As you can see, there are no properties that show the complete name of the user but you can also use the function called “concat” to concatenate the FirstName and the LastName like this:

concat(Value[Name = "LastName"]; ” “; Value[Name = "FirstName"])

In the future I will extend this form to add some features like Vacation Request or TimeSheet but I’ll keep that for later so stay tuned.

Guest Author: Pascal Poeck
SharePoint AfterWork

Pascal Poeck is a Team Leader SharePoint for an IT company based in Luxembourg specializing in SharePoint Technologies and RIA. He is also a Microsoft Ignite Trainer for SharePoint 2010, since november 2009 (IT Pro track), and a MCTS for SharePoint 2007 (DEV and ITPro). Pascal’s goal is to demonstrate how you can use SharePoint to provide a rich user experience with a minimum of code.

View all entries in this series: InfoPath and SharePoint»
Entries in this series:
  1. InfoPath and UserProfileServices: what can be done…
 

Please Join the Discussion

10 Responses to “InfoPath and UserProfileServices: what can be done…”
  1. Pat says:

    Very cool!

  2. @SPJeff says:

    UserProfileService.asmx rocks my world, one of my favorites tricks.

    On my DEV servers I like to modify the section of [web.config] under “\12\ISAPI\web.config” so the ASMX can be directly opened in the IE browser and executed manually to see raw XML output.

    Why?

    It allows me to find the property value and be very confident about the Field mapping. It’s very helpful for debugging on work I’ve done.

  3. Olaf Didszun says:

    That’s exacly what one of my customers asked me! I told him to use to UserProfile web serivce and you show me an excellent example. Thank you!

  4. RobD says:

    @SPJeff: That’s great, never knew you could do that to get all the properties!

    @Pascal: Great article. I’ve used the UserProfileService a number of times in Inforpath forms for First name and Last name, I didn’t realize all the other properties that were available. Great article and I look forward to the followup.

    The only thing I wish is that you could use secondary data connections in InfoPath 2010 forms when you use the “edit in infoPath” option on the auto-generated forms for a SharePoint 2010 list…

  5. Pascal Poeck says:

    Thank you for your comments guys.
    I’m actually working on the second part of this article so your comments are usefull to improve all that stuff ;-)

    • Beth Appel says:

      You can get the full name by using “PreferredName”, at least that is how it works on our SharePoint.

      • Any details on that, Beth? — Mark

      • Beth Appel says:

        I’m sorry I wasn’t clearer. In the step above where Pascal added the concat function to concatenate the first name and last name, use “PreferredName” instead. You can see it above in the list of default properties of the web service GetUserProfileByName.

  6. Pascal Poeck says:

    Totally agree with you Beth but you must be sure that the “PreferredName” property is complete in your user profile. The “LastName” and “FirstName” properties come from your Active Directory so you don’t have to care about them.

Trackbacks

Check out what others are saying about this post...
  1. Still Use E-mail Over SharePoint?; Google is Failing in the Enterprise; Microsoft’s Plan B for Phone…

    Top News Stories 10 Quotes on What SharePoint Really is (J. Boye) Microsoft SharePoint has been a large…




Notify me of comments to this article:


Speak and you will be heard.

We check comments hourly.
If you want a pic to show with your comment, go get a gravatar!