How to Create an InfoPath Form to Auto Populate Data in SharePoint 2010

How to Create an InfoPath Form to Auto Populate Data in SharePoint 2010

  • Comments 21
  • Likes

I have been working on a SharePoint 2010 site and the site owner wanted a form that would auto populate the current users information. Is this possible? Sure, but I’m not a developer so I had to figure out a different
way. This is where InfoPath 2010 comes in - although I’ve never worked with that product either. :-)

Researching on the Internet, I found some really good posts that I used to accomplish my task:

The SharePoint site is a repository of projects and people who sign up to help with the projects. We have the following lists:

  • Skills: pre-defined list of products/skills (i.e. SharePoint, Exchange, Development)
  • Projects: a list that is populated when someone starts a project
  • Resources: a list that is populated when someone adds themselves as a resource to work on projects

This post will provide step by step instructions on how to use InfoPath 2010 to create a form that will automatically populate users e-mail, first and last name, title, phone number, and manager.

Resources List

Create a custom list and create the fields as shown. Notice we are using “Single line of text” for the email instead of “Person or Group”.

The original “Title” column was renamed to E-Mail and requires unique values because I didn’t want someone to add themselves more than once.

The Skills column is a Lookup type that allows multiple selections tied to the Skills list.

The Title column is a new column is for the title of the resource.

 

Under General Settings, choose Advanced Settings. We need to change Item-Level Permissions and Attachments – all other settings are to stay at their defaults. Users should be able to read all items but only create and edit their own items; additionally we aren’t allowing attachments because they aren’t necessary for this list.

After you have the columns created for the list, it is time to customize the input form.

Customize InfoPath Form

From the Resources list, click the List tab then Customize Form.

The customize Form button will automatically launch InfoPath 2010 and will look similar to this. The red asterisks in the Fields pane indicate required fields. You can see the exact correlation on this form and our SharePoint list fields from above.

Enable SOAP Web Services

We need to enable the SOAP Web Services so we can pull information from the User Profile Service. Click the Data tab, From Web Service, From SOAP Web Service.

In the Data Connection Wizard, type the URL of your site and add /_vti_bin/UserProfileService.asmx to the end as shown and click Next

After the connection is made to the web service, scroll down to find the operation called GetUserProfileByName and click Next

Click Next on the Parameters dialog box

Click Next on the following screen

Enter a name for the data connection and click Finish.

On the right side under the Fields pane, select Show Advanced View

So far we have created our custom list, started customizing an InfoPath form and added the User Profile Service web services to the form. Now we have to create rules on what to do when the form loads.

Create Rules

Make sure you have the Data tab selected then choose Form Load. We will be using the Rules: Form Load section to create the rules and actions. Select the New button and choose Action. Our first rule is going to check the Account Name of the currently logged on user.

Account Name of Current User

Type a name for the rule under Details for then click the link under Condition that says “None – Rule runs when form is opened

In the Condition dialog box, click the arrow next to myFields and choose Select a field or group…

In the Select a Field or Group dialog box, change the Data source to GetUserProfileByName (Secondary)

Under myFields, expand queryFields until you find and select AccountName then click OK

Change the Condition is equal to” to “is blank” and click OK

Query for Data: GetUserProfileByName

In order get populate our form, we need to query the User Profile Services web service. In our Form Load data box, click Add to run an action and choose Query for data. Change the Data connection to GetUserProfileByName and click OK.

Next we need to get the data from the User Profile Services web service to populate our form with the current users’ data.

E-Mail Data

Click Add and choose Set a Field’s value

Click the expander  next to Field.

Ensure you are on the Main Fields then expand MyFields and select E-Mail and click OK

  1. Back at the Rules Details dialog box, click the Value icon  (this gets tricky :-))
  2. Insert Formula dialog box, click Insert Field or Group
  3. On the Select a Field or Group, change Fields to GetUserProfileByName (Secondary) and expand dataFields until you can select Value and click Filter Data
  4. On Filter Data, click Add
  5. In Specify Filter Conditions, change Value to Select a field or group
  6. In the Select Field or Group, and choose Name under PropertyData and click OK
  7. In the third box, change to Type Text… and type in WorkEmail and click OK on all the dialog boxes to create the rule

Let’s check to make sure we did this right. Click the Preview icon in the top left of the screen and you should see your email address populated in the E-Mail field

Remaining Rules

Follow the steps under E-Mail Data to populate the rest of the fields. When you are done, your form should have these rules applied.

Keep in mind that you are “GETTING” the data from the User Profile Service web service by using GetUserProfileByName (Secondary) to “PUT” data into your fields in the InfoPath form. Set the field on your form by getting the value and name
from the User Profile Service.

Default Profile Properties

This is a list of the default profile properties used by the User Profile Service that can be pulled and put into the InfoPath forms.

UserProfile_GUID

FirstName

LastName

PreferredName

WorkPhone

AccountName

Department

Title

Manager

AboutMe

Office

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

 

Publish the Form

After you have all the rules in place and have verified they work correctly, you can publish your form back to SharePoint. Simple click the X in the top right corner and choose Save and Publish.


The form will be saved to SharePoint, InfoPath 2010 will close and you will be taken back to the list from where you started customizing the form.

From here, click Add New Item. The Resources - New Item dialog box will open and you will see all the fields populated with the current users information.

The only thing the user has to do now is to select their skills and save the form.

I hope this helps others and a special shout-out to Itay Shakury and Clayton Cobb!

 

Comments
  • Firstly thanks for the information. It works great. However i have an issue whenever the form is opened again either to view or edit, it displays the current users information instead of the value of the person who completed the form in the first place.

    Any feedback would be appreciated.

  • Hi Jason - I had forgotten I had that problem, too. Change the Form Load rule's condition to DisplayName is blank and that should work.

  • Hi, thanks for pointing me in the right direction on this.  I was going around in ever-decreasing circles.  However, it's a case of one-step forward, two back at the moment!  I can preview the form, and everything is fine, i.e. my form is populated with user data and manager data, as expected, but as soon as I publish to the SP Server, I get the following error on running the form.  

    An error occurred querying a data source.

    Click OK to resume filling out the form. You may want to check your form data for errors.

    Show error details

    I am a Farm Administrator, so jsut wondered if you had any ideas what is going on.  If I click on OK, the form appears, BUT none of the data is populated as it is in preview.  

    HELP!  Thanks

  • Hello,

    Thank you for this fabulous tutorial, it's really helped me out!

    I just have one question, as per the diagram (blogs.technet.com/.../5127.RemainingRules.jpg )

    I want the managers email being pulled through, but I can't seem to get it? I see a new query has been added with GetUserProfileName but that just autopopulated the manager field with my own email address.

    Any help is much appreciated!

  • Hi can it implement in infopath, like i want to display the list items in infopath itself. if i select emp id, should display automatically all the info related that employee in infopath itself.

  • Firstly thanks for the information. It works great. However i have an issue whenever the form is opened again either to view or edit, it displays the current users information instead of the value of the person who completed the form in the first place.

  • Hi,

     Thanks for the article and it is very useful information. I am having the issue that the look up field has to load more than 5000 records and it takes more time to load the form and sometimes it is loading the partial data. Is it anyway to modify the query or need to do something to fix the issue?

  • Really good, works perfect first time (even though I have no idea what I have actually done).

  • Thank u...Very usful

  • very nice ..very helpful.

  • Follow the steps and no value to populate in preview. Any idea?

  • I new to this and I've already created a form in InfoPath and connected it to the forms library.  I have several fields that I want to auto-populate.  Where do I start use the information provided?

  • Im trying to create a form in which the intial form is create but then I want to create a workflow inwhich the form is sumitted and then a nother form within the worklfow appears and the information that was in the previous form appears in the secondary form. Is this posisble?

  • Is it possible to pull in the, say 'Title' field of another user that is determined based off of a people picker? Say I'm trying to create a form that I'm selecting someone's new supervisor and I want to populate that user's 'Title' or 'WorkPhone' field after I select it using a people picker. Is that possible?

  • Thanks Anne!

    Here's a related post on InfoPath 2010 Best Practice Querying User Profile Web Service:

    www.sharepointbreak.com/.../infopath-2010-best-practice-querying-user-profile-web-service

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment