Monday, July 03, 2006

InfoPath 2007: Form Template Parts

In InfoPath 2007 it will be possible to reuse forms by creating Form Template Parts.
You can compare those Form Template Parts with regular forms, which you can reuse into other forms.

Form Templates Parts Step by Step

For example: You have several forms which contains customerdata. It would be a lot of work to copy & paste all fields, conditional formatting and rules. If you have 10 customer datafields (name, address, postal code, ...) which will be reused on 5 forms, you have to manually adapt your main data source in each form in InfoPath 2003.

Now, in InfoPath 2007 we can create a separate form which contains our customer datafields and we save the template as an .XTP file.

1. How to create a Form Template Part ?

Open Office InfoPath 2007. Open the File menu and select 'Design a form'.
Select 'Design a new Template Part'. (we will base our example on a 'blank' form template)

Now, It seems that InfoPath has created an empty form for you, but it isn't.
This will be our Form template Part, which will be reused on other forms.

2. Managing data structure of a Form Template Part

You can add new datafields to your template by drag & drop some controls on your form.
You can also manually insert, update or remove datafields when you select 'Data Source'
in the Design Tasks taskpane. The root of you template will also be named 'myFields'.

I suggest you change the myFields root element into a more specific name like 'customer'.
The form which will reuse this template will copy this root element and his child elements into its form.
So it is usefull to change the root element in a understandable name for reuse.

3. Designing your template

You can design your form in the same way you design a regular form in InfoPath 2007.
You can add conditional formatting to manage the color or the visibility (hide/show/disabled) of your components.
You can also add some rules or data validation handlers to process your data.

4. Save your template

The template you have made, will be saved as an XTP file on your harddisk.
You can save your template in the same way you did by forms.

5. Reuse the template

Now you have to create a new form which will be based on our template.
Open the File menu and select 'Desig a form...'.
This time you will 'Design a new Form Template' based on a 'blank' form.

Before you can use your template, we have to import the Form Template Part as a custom control.
Open the 'Controls' panel in 'Design Tasks'. In InfoPath 2007 you will find a new item in this controls list which is called 'Custom'. You can import your template by clicking on 'Add or Remove Custom Controls...'
Point to the right template location on your harddisk and add the template as a custom control.

Drag & drop your created custom control on the screen.
The root and its child elements will be copied from the template into the main datasource of your form.
It is also possible to drag and drop more than one occurence of your template in the form.
InfoPath will automatically add '_x' to the imported datastructure to identify every field as a unique item.
(replace the x by a number starting from 1, 2, 3, ...)

Save and publish your form. The Form Template has been successfully integrated in your form.

6. Download the Customer example

You can download an example including an .xsn form which is based on a .xtp template.
The Word 2007 document will show you some screenshots.
(Data logic will not be added to the form, because it isn't relevant in this exercise)

Invoice form

Customer Template

Screenshots (Word 2007)

Example Invoice (without data logic)
invoice example