Hi, habravchane!

Business processes and workflow in any organization require the filling of a variety of forms and forms. The task of automating these processes involves, inter alia, replacing the antediluvian paper forms with electronic analogues. It uses a lot of very different tools and technologies: forms based on Excel documents, forms based on Access, web forms of asp.net applications, corporate desktop applications.
As part of the MS Office package, there is a program specifically designed for creating electronic forms - this is Microsoft Office InfoPath.
')
I will talk about the basics of developing InfoPath forms. The focus will be on basic things, but in conclusion, some deeper aspects will be mentioned, such as data connections, programming in InfoPath forms and integration with Sharepoint.
Concept
The underlying principle of InfoPath forms is the separation of a form template and its data.
- A form template is a file with the .xsn extension, containing a description of the structure of the form and its design. With some stretch you can take it as an empty form without data.
- Form data is an xml file containing specific information. This is a useful "filling" of the form.
In accordance with this division, InfoPath appears in two ways: the designer for developing templates and the client for opening and filling out forms based on templates. Up until InfoPath 2007, this functionality was combined in one application. In the version of Office 2010, the application is divided into two independent components: InfoPath Designer (Form Designer), designed to develop templates and InfoPath Filler, which fill out specific forms based on templates. Examples in this article will be for InfoPath 2007.
Typically, a form template is published in a well-known place from where it can be accessed by users. Users open a template and fill out a form. Further actions may be different: saving the completed form as an .xml file, sending information somewhere.
Saved as a .xml file, the form can be opened and modified. It is clear that the .xml file must “know” where the corresponding form template is located, because the structure and design of the form are defined in the template. If the template is not available, InfoPath will take it from the cache, if it has changed, you will be given the opportunity to download the updated template. To provide links between a form template and its data, InfoPath has a complex architecture for publishing form templates.
Simple example
The best way to figure it out is to touch it with your hands. For a start, you can experiment with the ready-made “sample” forms with the program. Open Microsoft Office InfoPath 2007. If the Getting Started window appears, select “Set up sample” on the left, if it doesn’t appear, go to the “File” menu, select “Form Designer ...” and in the window that opens, again click on the "Customize Pattern ..." button to the left. Take, for example, the sample "Asset Accounting".

After double clicking on the sample, InfoPath will open it in designer mode. You can edit the form template, delete unnecessary fields, add new ones, etc. The panel with the available components (input fields, checkboxes, drop-down lists) can be opened via the “Controls” link on the taskbar in the right part of the window.

Let's save our template in a convenient place as the “Asset Accounting.xsn” file. Perhaps at the same time InfoPath will remind you that it would be good to publish it - but for now let's not do it.

Now you can open the template and fill out the form.
After filling, you can save it. This will already be a file with the .xml extension - a data file based on our template. This way you can fill out many forms based on one template.

Publication
As already mentioned, InfoPath has a complex architecture for publishing form templates. The asset accounting form template, which we have saved somewhere on our computer, is available only to us. I would like to make it accessible to a larger circle of users.
First, open the form template in design mode (the “Designer” item from the context menu of the file).
The Publish Wizard is launched by the "Publish ..." command from the "File" menu.
InfoPath provides several options for publishing a form. In this case, let's lay out the template in a shared folder.

In the next wizard window you need to specify the place of publication. At one time I suffered at this step. Not quite understanding the meaning of the actions performed, I clicked on the “Browse” button and selected the saved template file there. This is not necessary. In the "Path and file name for the form template" field, the path to the file that does not yet exist should be indicated in the place where we want to publish it. Therefore, click "Browse", we reach the shared folder, and in the "File name" field we drive in the name of the future published template, and then click "OK".



In the next step, you need to enter an alternative way to access the published template from the users. After all, the mapping of network resources may differ from the developer and the end user. The network resource seen by end users may be different. And InfoPath requires that access to the published template is uniform. Therefore, when publishing, two paths are specified — one for the administrator (we have already defined it), and the other for the end users. If the path on the part of the user is no different, simply copy the path that we indicated in the previous step into the input field.

After clicking on the “Next” button, we check the entered data and click “Publish”.
In the final wizard window, you can enjoy the message about the successful publication and ask to immediately open the form based on the published template in order to make sure that everything is in order.

Security
In the final windows of the publication wizard you can see the line “Security level: Domain”.
The security level of a form determines what form is allowed to do, what is the level of trust in it.
This is set when developing a form template on the “Security and Trust” tab of the “Form Settings” dialog box, which is opened by the same command from the “Tools” menu. There are three possible levels of trust: limited, domain level and full trust.
- Forms with a limited trust are not very useful, they cannot access external data sources, they cannot even be published in a shared folder, which we did with the asset accounting form template. However, templates with limited confidence can be sent by e-mail, and recipients will be able to fill out forms based on them. By the way, when you send an InfoPath 2007 form by email, you can do this in two ways. The first is to send the form as an attachment. This can be done regardless of which email clients are used by the recipient and ours. The second possibility is to send the form in the message body. This is possible if both we and the recipient have an email client - Microsoft Office Outlook 2007.
- Forms with a domain security level can access content within a domain, for example, populate drop-down lists from directories stored in an MS SQL Server database or from Sharepoint lists.
- Full trust means that the form can do anything. In particular, if a form has program code (event handlers, etc.), it must have a full level of trust. Templates with a full level of trust must be signed - this can be done here (checkbox “Sign this form template”, buttons for creating and selecting digital signature certificates).
By default, the “Automatically detect security level” checkbox is selected on the Security and Trust tab. From experience, I can say that it is automatically determined by far not always automatically: a significant part of errors when opening a form based on a certain template was caused precisely by the fact that the template had a low level of security.
Little by little
Data sources
As already mentioned, the InfoPath form can access external data sources. This can be a database (MS Sql or Access), a Sharepoint list, a web service, .xml file. The most obvious use is to populate drop-down lists based on various directories.
Let me remind you that the form template that accesses external data sources must have a security level - domain.
In fact, the structure of the InfoPath form itself is determined by the data source. Even if a form template is created from scratch, all the same, there will already be one in the data sources - the “primary” data source. When adding elements to the form, the corresponding nodes will be added to the data source. Any data source in InfoPath is represented by an xml-tree, and thus the structure of the form is essentially an xml-tree.
It is possible to create InfoPath forms based on some of the available data sources - web services, databases, predefined xml schemas. In this case, we will not be able to change the data source, which is the basis of the structure of the form, and we will not be able to add new fields that are not in the data source.
Representation
A form can have multiple views. A view is a kind of “slice” that includes a specific group of fields. After all, it is not necessary to simultaneously display on the form all the fields of its data source. If there are many fields, you can group them by meaning and divide them into several representations. In addition, you can create different views for different user groups that will work with the form as part of a business process. Finally, you can create a separate presentation for printing the form, which will have a particularly beautiful design, focused specifically on this task. You can switch between views using the InfoPath client’s View menu, in which the form is open, and, for example, programmatically, for example, by clicking the buttons on the form (you can, on the contrary, disable the ability to manually switch through the View menu ).
Programming
Complex forms can contain program code (managed code in C # or Visual Basic .Net is of most interest). Let me remind you that the level of security of such forms should be “Full trust”. In the code, you can, for example, perform the necessary event processing, complex control of the input data (in addition to simpler validation, which can be configured through the InfoPath designer interface). It is possible to dynamically change the interface and form elements, add and hide certain input fields, switch between views. You can programmatically connect to such data sources, connection to which is not provided in the InfoPath constructor (for example, to an Oracle database).
Sharepoint Integration
A bunch of InfoPath forms and Sharepoint is probably one of the most promising and widespread applications of InfoPath forms today. Let's say my acquaintance with InfoPath happened quite recently in the process of studying the development of workflows (Workflows) for Sharepoint. For many years before, InfoPath lived quietly on my computer as part of the MS Office suite, without attracting attention to itself.
So, what about InfoPath integration with Sharepoint?
- The form template can be published as a Sharepoint form library. In this case, when publishing on the Sharepoint site, an InfoPath form library is created, based on this template. Users will be able to fill out forms and add them to the library.
- In continuation of the previous paragraph, the InfoPath Forms Services service, available in MOSS 2007 (Microsoft Office Sharepoint Server 2007), allows you to fill in InfoPath forms right in a browser window. In this case, users do not have to install the InfoPath application - they will be able to fill out and add forms to the form library using only the browser. Unfortunately, InfoPath Forms Services is available only in MOSS, in WSS (Windows Sharepoint Services) this service is not available. Another limitation is that far from all the capabilities of full InfoPath forms can be used in forms compatible with InfoPath Services: in order for the form to be displayed directly in the browser, you have to give up some controls (pictures, ActiveX controls, block “Main / Details”, bulleted and numbered lists, and others), and when writing program code for such a form, deal with a greatly reduced object model (mainly, the possibilities associated with dynamic changes Niemi form elements).
- Publishing a template as a form library has one drawback - the impossibility of reuse. If we need another library, we will have to publish again. Fortunately, you can publish a form template as a Sharepoint content type and create any number of form libraries on its basis.
- InfoPath forms can be used as Sharepoint workflow forms. About Windows Workflow Foundation (WF) and workflows on Habré has already been written . The Sharepoint Platform (both WSS and MOSS) offers a WF-based workflow infrastructure for lists, libraries, and content types. For example, you can create a workflow for approving documents (yes, the same InfoPath forms!), Which will be launched when a document is added to the library. A workflow involves creating tasks for users or groups of users (in this case, they are tasks that approve the added document). When designing a workflow, it is necessary to create various forms that need to be completed at different stages of the life cycle of the workflow: when the workflow is associated with a list, when the workflow is started, when performing the assigned tasks. And these forms of Sharepoint workflow can be both classic asp.net pages and InfoPath forms.
- Finally, it is through InfoPath forms that metadata are entered when loading and editing documents in document libraries on the Sharepoint site. The figure below shows a Word document that has an information bar for entering metadata — the Author, Title, Subject, and other fields. This panel is nothing more than an embedded form of InfoPath. If you wish, you can customize such a form, replace it with your own handwritten design, if something that does not suit the one that was generated automatically for a given document library does not suit you.

Afterword
In this article, I tried to briefly describe the development of electronic forms using InfoPath, focusing mainly on the Microsoft Office version of InfoPath 2007. Many questions are mentioned only in passing, other aspects remained completely unaffected - primarily because I myself encountered InfoPath- forms are relatively recent and the process of studying them is far from complete. This process could be much more laborious without one book, which served me as the main source of information on the topic - this is Phil Janus' book “InfoPath 2007 for Professionals”.
- Janus, Philo. InfoPath 2007 for professionals .: Trans. from English - M .: LLC “I. D. Williams, 2009. - 272 pp., Ill. - Paral. tit English ISBN 978-5-8459-1484-2 (Russian)