Search This Blog

Thursday, March 29, 2012

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

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

No comments:

Post a Comment