How to: Customize External List Forms Using Microsoft InfoPath
Last modified: April 16, 2010
Applies to: SharePoint Server 2010
Microsoft Business Connectivity Services (BCS) generates default SharePoint forms for viewing, creating, and editing items from an external list automatically. However, customization options on these basic Web Part forms can be limited. If you want to perform rich customizations or add declarative rules or business logic to the forms, you can replace the default SharePoint Create, View, and Update forms of an external list by using Microsoft InfoPath 2010 forms.
To replace the default SharePoint forms with InfoPath forms
In your browser, navigate to the external list.
On the Server ribbon, click Edit List. The external list opens in Microsoft SharePoint Designer 2010.
On the ribbon, click the Design Forms in InfoPath button, as shown in Figure 1.
Design the form as you need with items such as custom types. Controls for simple fields are autogenerated; however, for complex types, you must drag your own controls from the toolbox.
When you are finished, on the File menu, click Quick Publish to republish the form to the server.
Now you can navigate to the external list and create an item or view an item. The form that is displayed is the new InfoPath form instead of the default SharePoint form.
Customizing the Look and Feel of Forms
You can customize the appearance and behavior of your external list forms by using InfoPath. In the video, InfoPath 2010 - Customize a SharePoint List Form, Daniel Broekman, a program manager on the InfoPath product team shows how you can customize a SharePoint list form quickly by using InfoPath 2010. You can follow the same procedure shown in the video to replace a default SharePoint external list form with an InfoPath form, and customize it to change its appearance and behavior.
Adding Declarative Rules or Business Logic to Forms
You can add declarative rules or business logic to the form in InfoPath without writing code. For example, you can create a rule to limit entry of a postal code to five digits (12345), or to have users enter telephone numbers in a certain format. The video InfoPath 2010 - Customize a SharePoint List Form also shows how to add declarative rules and business logic to your form.
Rendering Complex Types
A scenario in which replacing a SharePoint form with an InfoPath 2010 form is most useful is when you want to render and edit complex types that are defined in an external system. For example, consider an Address field that is returned by a SpecificFinder of an external content type. This Address field can be a complex type in the external system, which contains several subtypes, as shown in Figure 2.
Notice the warnings displayed in SharePoint Designer. If Microsoft Business Connectivity Services (BCS) discovers this kind of complex type in a return parameter of a SpecificFinder, it ignores this field in the regular SharePoint external list form. Figure 3 shows the default View Item page of an external list that contains this Address complex type. Notice that the Address field is skipped and is not shown in the form. Also, if Address is a required field for Create or Update operations in the external system, you cannot create or edit Customer items.
In such a case, you can convert the form to InfoPath. Because the SpecificFinder has a complex type (Address in our example), Business Connectivity Services does not create the form with all of the required fields and controls. Instead, it creates a blank InfoPath form without adding the fields to the form, as shown in Figure 4.
To resolve this issue, you drag dataFields fields from the Fields section in the task pane. However, this works only if all of the subtypes of the complex type can be displayed by using the controls that are available in InfoPath. For example, in our Address example, all its subtypes can be displayed by using a Text field control.
If a complex (or custom) type or one of its subtypes cannot be displayed by using any of available controls in InfoPath, you must design a custom InfoPath control and use it to display that field. If you add a custom InfoPath control, you cannot publish the form to the server.
After you design the form, you can save the form and do a quick publish to the current location. The external list form starts to show all the fields. Figure 5 shows the external list View Item form after it is converted to InfoPath. The only action here was to drag the dataFields controls into the design area of the form.
Notice that the Address field and all of its subtypes are displayed. If the external content type has defined Create and Update operations, you can create and edit customer items by using the external list forms.
Embedding an External Item Picker Control
For scenarios where a user needs to pick an external item, such as customer John from a list of customers, InfoPath 2010 provides an External Item Picker control that you can use to embed a picker in a form. An External Item Picker provides picking and resolving functionality for external items on the server and in rich-client Microsoft Office applications.
If you set up associations for external content types in the BDC Metadata Store and the external list form for one of the external content types that contains a foreign key, Business Connectivity Services automatically adds a picker control to the form for that field. For example, consider a customer/order scenario. Let's assume the external content types and the association are already set up. If you upsize the Order external list form to InfoPath, Business Connectivity Services by default puts an External Item Picker control for the CustomerID field in the Order form. This enables users to easily find the customer they want when working with orders.
However, if your autogenerated InfoPath form is blank because the SpecificFinder has one or more complex types, then you must drag an External Item Picker control from the ribbon and set the required properties. For information, see How to: Embed an External Item Picker Control in an InfoPath Form.
Creating Multiple Views of a Form
Your external list InfoPath form can have multiple views. This is particularly useful in write-once scenarios where the external system does not enable you to update a field after it is created. In such cases, you can create two views, one for the Create operation, and the other a read-only view for the Update operation. You can update the .aspx pages for Create and Edit to show the correct view of the form.
Adding Code-Behind or Rules
Finally, you can add code-behind or rules to your InfoPath form. (For information about how to add code-behind to an InfoPath form, see the InfoPath 2010 Developer Reference for Form Templates. For information about how to add rules to an InfoPath form, see InfoPath 2010 Help. You can add code-behind or rules to perform additional business logic to the data entry. For example, you can add code-behind or rules to ensure the postal code that is entered is a valid U.S. postal code or ensure that the country/region code is valid. You can also use the Business Connectivity Services object model in the code to access to the external system or the BDC Metadata Store in your code. Forms with code-behind need full trust on the client and require administrator rights.