imageWhile the contacts list is usually filled out for contacts that are outside the company, there are times when you would use a contacts list to store internal and external resources.  Wouldn’t it be nice if you didn’t have to re-type your internal contacts’ information that are already in the system?  Now you can with a little InfoPath customization on the contacts list. 

Here’s our plan:

  • Create the contacts list, and open in InfoPath
  • Create a data connection to the User Profile web service
  • Customize the form adding some text, a people picker and a button
  • Create InfoPath rules that will populate the contact fields from the user fields in the User Profile store

Let’s get going!  Before we begin, make sure you have InfoPath 2010 installed locally on your computer.  I also want to give credit Laura Rogers and Darvish Shadravan’s book Using Microsoft InfoPath 2010 with Microsoft SharePoint 2010 Step by Step.  I know it looks like a lot of steps, but it’s easy once you get the hang of it.

  • So obviously we need a contacts list.  If you don’t already have one, go to the SharePoint site where it will live, and create a contacts list.
  • From the list, click the List tab on the ribbon, then click Customize form:

Customize form

So now we have our form open in InfoPath 2010.  Let’s add our elements to the form. 

  • Above all the fields, let’s add some text instructing users what to do with the the field we’re about to add (.e.g To enter an existing user’s information, choose the user below).
  • Insert a people picker control by clicking the Person/Group Picker control in the Controls section of the ribbon.  This will add a column to the contacts list called group.
  • Below the people picker, insert a button control from the same section of the ribbon as above.  With the button still highlighted, click the Control Tools|Properties tab on the ribbon.  Then in the Label box, change the text to something more appropriate to our task (e.g. Click here to load user data!).
    • You can drag the button control a little larger to account for the text.

We should end up with something like this:

Customized infopath list form

Before we can populate the fields with user data, we need to create a connection to the User Profile Service.

  • Add a data connection to the User Profile Service
    • Click the Data tab on the ribbon, and click the option From Web Service, and From SOAP Web Service.
    • For the location, enter the URL of your SharePoint site in the following format – http://<site url>/_vti_bin/UserProfileService.asmx?WSDL.  Click Next.
      • Note - for the URL, it can be any SharePoint site URL, not just to the site where your list is.
    • For the operation, choose GetUserProfileByName.  Click Next.
    • Click Next on the next two screens.
    • On the final screen, uncheck the box for “Automatically retrieve data when form is opened”. This is because we are going to retrieve the data when the button is clicked, also for performance reasons.

Now we need to wire up the actions on our button to populate the fields with the information for the user in the people picker control.

  • Tell the form to read the user from the people picker control
    • Click the Home tab on the ribbon.
    • Click the button control we created, and under the Rules section of the ribbon, click Manage Rules. Notice the pane appear on the far right.
    • In the Rules pane, click New –> Action. Change the name to something like “Query and load user data”.
    • Leave the condition to default (none – rule runs when button is clicked).
    • Click the Add button next to “Run these actions:”, and choose “Set a field’s value”.
      • For Field, click the button on the right to load the select a field dialog.  Click the Show advanced view on the bottom.  At the top, click the drop down and choose the GetUserProfileByName (Secondary) option.  Expand myFields and queryFields to the last option and highlight AccountName.  Click ok

infopath accountname

      • For Value, click the formula icon. On the formula screen, click the Insert Field or Group button. Again click the show advanced view link, but this time leave the data connection as Main. Expand dataFields, then mySharePointListItem_RW.  At the bottom you should see a folder called group (the people picker control we just added to the form).  Expand this, then pc:Person, and highlight AccountId.  Click Ok twice to get back to the Rules pane.

infopath accountid

If we didn’t do this and just queried the user profile service, it would load the data of the currently logged in user.  So we need to tell the form what user to load the data for.  We take the AccountID field from the people picker control and inject into the AccountName query field of the User Profile Service data connection. 

  • Load the user profile service information for the chosen user
    • Click the Add button next to “Run these actions:, and choose Query for data.
    • In the popup, for Data connection, click the one we created earlier – GetUserProfileByName and click Ok.

We’re closing in on our goal.  Let’s see our progress.  We should see something like this:

infopath add rule

Now that we have the user’s data read into the form, we can populate the fields in the contact form.  The number of steps to complete will depend on how many fields you want to populate.  We need to add an action step for each field.  I’ll show you one example and then you will just repeat the steps for the other fields.  Let’s update the Job Title field.

  • Populate the contact form fields with existing user’s data
    • Click the Add button next to “Run these actions:”, and choose “Set a field’s value”.
      • For Field, click the button on the right to load the select a field dialog.  Highlight the field Job Title.
      • For Value, click the formula icon. On the formula screen, click the Insert Field or Group button.  Click the Show advanced view on the bottom. At the top, click the drop down and choose the GetUserProfileByName (Secondary) option.  Expand the fields all the way down until you see the Value field.  Highlight it but don’t click ok, but click the Filter Data button, then Add
      • For the first dropdown that says Value, choose Select a field or group.   The value field will be highlighted, but click the field Name field under PropertyData.  Click Ok
      • In the blank field after “is equal to”, click in the box and choose Type text.  Then type the text Title
      • Click ok until you get back to the Manage Rules pane.  The last previous screen will look like this.

infopath rule field value

We’re going to update common fields that are in the user’s profile, and likely from Active Directory.  You can update fields like first and last name, company, mobile and work phone number, etc.  For the other fields, the steps are the same except the Field you choose to update from the form, and the very last step where you enter the text will change.  Here’s what the rules look like when we’re done:

infopath rules

We’re all done, good work!  You can preview the form and try it now.  Click Ctrl+Shift+B to preview the form.  Once you’re satisfied, you can publish the form back to the library.  Click File –> Quick Publish.  Once it’s done, you will get confirmation:

infopath quick publish

Now open your form in SharePoint.  From the contact list, click Add new item.  Type in a name, and click the button and watch the magic happen!