Published: 24 May 2010
By: Manning Publications

This article is taken from the book SharePoint 2010 Workflows in Action. This article shows you how to customize SharePoint's out of the box forms using InfoPath.



About the book

This is a sample chapter of the book SharePoint 2010 Workflows in Action. It has been published with the exclusive permission of Manning.


Written by: Phil wicklund
Pages: 400
Publisher: Manning
ISBN: 9781935182719

Get 30% discount

DotNetSlacker readers can get 30% off the full print book or ebook at www.manning.com using the promo code dns30 at checkout.

A new feature in InfoPath 2010 lends the ability to customize SharePoint's out-of-the-box forms. These forms are fast and easy to implement, but aren't always adequate for the job. That's where InfoPath comes in-customizing an out-of-the-box form is often more efficient than building a form from scratch.

Before deciding, you should consider how you plan to store the new form. A form in a form library stores data as XML. When you customize an out-of-the-box form, that data still needs to be mapped to columns in the list item. If you have a lot of data you may want to go the form library route, rather than add 20 plus columns to the list item. However, you may just want to change the behavior of one or two columns, or possibly brand the form a bit with a company logo, or more detailed instructions. In this case, customizing the out-of-the-box forms is a great approach. For this article, we will customize an out-of-the-box form by enabling dynamic dropdowns. In other words, selecting an item from one list will update the items in a second list. InfoPath makes this customization possible.

SharePoint Server required when customizing the out-of-the-box forms

There are two main versions of SharePoint 2010, SharePoint Server and SharePoint Foundation. This section depends of features available only to the Server edition of SharePoint 2010.

To get started, create a SharePoint list or library, and add all the columns you need to track to that list. You can do this through the List Settings and then Add a column option. After you have all your columns setup, you're ready to edit the form to suite your user interface requirements. When in the ribbon, in the List tab, click the Customize List drop down and choose Customize Form (see figure 1).

Figure 1: To customize the out-of-the-box forms in a list or library, click the Customize Form button in the ribbon to launch InfoPath.

To customize the out-of-the-box forms in a list or library, click the Customize Form button in the ribbon to launch InfoPath.

Clicking this button will launch InfoPath, which defaults to a view that includes all the columns in the list you're trying to edit. The example we're going to build involves a tasks list, and each task has an associated Project and Sub Project. Specifically, we'll make the lookup columns dynamic. That way, the Project and Sub Project items will update according to selected parent Project. Figure 2 shows the tasks form in InfoPath.

Figure 2: When you customize an out-of-the-box, InfoPath loads all the columns in that list or library. Now you can start editing their behavior and the way they look.

When you customize an out-of-the-box, InfoPath loads all the columns in that list or library. Now you can start editing their behavior and the way they look.

The Parent Project column is a lookup column to a separate list called Project Names. Sub Project is also a lookup column to a second list called Sub Project Names. The Sub Project Names list has two columns, Title and Parent Project. The first thing we need is a new data source for the Sub Project drop down. The default data source for this drop down has two fields in it, Title and ID. However, since we need to filter on the Parent Project column, we need to add a new data source. We'll then filter the new data source on the selected Parent Project. To complete the task, we'll add a rule to the Parent Project dropdown that updates the data source each time the dropdown changes.

1. Setup a new data source for the sub project dropdown menu:

A) In the Data tab within the ribbon in InfoPath, click the Data Connections button. Click the Add button to add a new data source.

B) Select the radio buttons to create a new data source that receives data. Click next.

C) Choose to receive data from a SharePoint library or list. Click next.

D) Type the URL to the SharePoint site that contains the library or list. Click Next.

You'll be half way through the new data source creation wizard. Continue with step 2 to complete the wizard.

2. Specify your list and columns to be included in the data source:

A) Select the list name that contains the data for your connection. In this case, Sub Project Names. Click next.

B) Select the columns to include in the data source, in this case Title, Parent Project, and ID columns. Click next twice.

C) Give the data source a name, like Sub Projects Filtered by Parent Project Selection. Click Finish to complete the data source wizard, and thereafter Close.

A new data connection will be available. Change the Sub Project dropdown to use this data connection instead of the default connection. Right-click the dropdown and choose Drop Down List Box Properties. Change the Data Source dropdown menu to the data connection you just created.

3. Filter the new data source on the selected Parent project. In the entries box directly below the Data Source selection on the Sub Project dropdown, you'll see the XPath query that points to the data. Click the Select XPath button directly to the right of the text box (click the ellipses image). Follow these steps to setup the filter:

A) In the Select a Field or Group dialog box, click the Filter Data button and then click Add.

B) The first dialog box contains the fields in our custom data source. Select the Parent Project field. Leave the comparing field (middle drop down) set to "is equal to".

C) In the third dropdown, choose Select a field or group. In the resulting dialog box, change the Fields dropdown to Main. This is the data that is represented on the form itself.

D) There are two sub folders. The queryFields folder will query fresh data, and dataFields folder contains the current data. Expand the dataFields folder.

E) Expand the sub folder containing the list item data. Then, select the Parent Project field and click Ok 5 times.

4. Now our Sub Project dropdown is correctly filtering its data based on what the Parent Project dropdown's selected value is. The last thing we need to do before we publish the form into our SharePoint tasks list, is to create a rule on the Parent Project dropdown.

A) Right click the Parent Project dropdown, and choose Manage Rules under Rules.

B) Click the New dropdown in the Manage Rules tool bar, and select Action.

C) Give the rule a name, like Update Sub Project Dropdown.

D) Click Add and select Query for data.

E) In the Data Connection dropdown, select the custom data connection you created earlier, in this case, select Sub Projects Filtered by Parent Project Selection. Click Ok.

With the rule in place on the parent project dropdown, the data source for the sub project dropdown will update each time the parent dropdown changes.

That's it! Now all that is left is to publish the form back into our tasks list. Under the File menu in the Info tab, click Quick Publish. Now when we go to create a new task in our tasks list, our Sub Projects dropdown will dynamically populate, based on which Parent Project is selected (see figure 3).

Figure 3: You can customize the out-of-the-box new and edit forms to make lookup columns in your lists or libraries dynamically generate their items based on custom rules.

You can customize the out-of-the-box new and edit forms to make lookup columns in your lists or libraries dynamically generate their items based on custom rules.

Get 30% discount

DotNetSlacker readers can get 30% off the full print book or ebook at www.manning.com using the promo code dns30 at checkout.

<<  Previous Article Continue reading and see our next or previous articles Next Article >>

About Manning Publications

Manning Publication publishes computer books for professionals--programmers, system administrators, designers, architects, managers and others. Our focus is on computing titles at professional levels. We care about the quality of our books. We work with our authors to coax out of them the best writi...

This author has published 33 articles on DotNetSlackers. View other articles or the complete profile here.

Other articles in this category


Developing a Hello World Java Application and Deploying it in Windows Azure - Part I
This article demonstrates how to install Windows Azure Plugin for Eclipse, create a Hello World appl...
Android for .NET Developers - Building a Twitter Client
In this article, I'll discuss the features and capabilities required by an Android application to ta...
Ref and Out (The Inside Story)
Knowing the power of ref and out, a developer will certainly make full use of this feature of parame...
Developing a Hello World Java Application and Deploying it in Windows Azure - Part II
In this article we will see the steps involved in deploying the WAR created in the first part of thi...
Android for .NET Developers - Using Web Views
In this article, I'll show a native app that contains a web-based view. The great news is that HTML ...

You might also be interested in the following related blog posts


Outlook Send Mail Infinite Loop Message in Outbox read more
Developing RESTful services with JSON and POX support in the ASP.NET MVC read more
MVC Controllers and Forms Authentication read more
Script to Inventory Print Servers read more
Value of site monitoring read more
Using LINQ to query Outlook emails joined with SQL data read more
SharePoint 2007 Workflows - Adding a user input form read more
Orcas Office development through pictures read more
Watch out: DebugView (OutputDebugString) & Performance read more
Sorting the Visual Studio "Add New Item" Dialog with PowerShell read more
Top
 
 
 

Please login to rate or to leave a comment.

Free Agile Project Management Tool from Telerik
TeamPulse Community Edition helps your team effectively capture requirements, manage project plans, assign and track work, and most importantly, be continually connected with each other.