This post explores the capabilities of the integration between InfoPath 2007 + Nintex Workflow 2007. The idea is to create a form which is handled and modified by the Workflow. In order to do that, some customization on the form is needed to show and allow the users to manipulate the data on the form.
Bellow I will explain the step by step how to create this form and the workflow to manipulate it. It's necessary some coding behind the form, in order to control the default view of the form.
1. The first step is to create a new InfoPath 2007 form, and in the default view, add some elements, as in the screenshot bellow. The information isn't the most important part of this example, so you can add the fields you want. In my case I created a title and added 2 fields: Name and Birthday.
2. In order to simulate different steps, controlled by the workflow, it's necessary to create other Views in the current form. To do it, in the Design Tasks, click in the Views option. Now, we need to create more 2 Views: View 2 and View 3. In order to change between these Views, use the menu: View.
3. Go to the View 2 and add some components on the screen. In my case, I added a Text Field, gave the name comments, and defined in the Display options to be Multiline.
4. When you work with an InfoPath form, the data input of the form is called Data Sources, and it's shared between the Views. In our last View, We will create a Summary, showing the information of the other 2 views. To do it, we need to go to the Design Tasks, and click in the Data Source Option. On this screen, just simple drag and drop the fields to the View 3.
5. Now it's time to do customize the template. The first thing we need to do is to create a new Field on the form. I created the field currentView, type text, and default value 1. This field is responsible by controlling the current view the user will be able to see and handle. We don't need to show it on the form, it's just a logic field.
6. It's publishing time! We need to publish the form on SharePoint, because later we will create some C# code on the form and we can't publish directly (only if we want a web-based form, for regular forms, it works). The publishing is a "Next, Next, Finish" wizard where we need to define the SharePoint site to publish the form, and create a new Form Library for it. I gave the name InfoPath Steps in my example. The most important step of the publishing is the last one, where the columns of the Libraries are defined. When an InfoPath form is published, the fields of the form can became metadata on the SharePoint List/Library. On the screen below, we need to enable the field currentView to be edited externally of SharePoint. In this way, the workflow is able to modify this field, and then control the form.
7. After publishing the form, we can continue modifying it. On the menu, click on Tools> Programming> Microsoft Visual Studio Tools for Application. The idea here is to control the current view of the form. On the Visual Studio, insert the code bellow (I found this approach here: http://support.microsoft.com/kb/826997/en-us)
8. Now we need to enable the fields based on the current view. To do it, go to the View 1, click on the Name textbox with the right button, and select Conditional Formatting. Add a new, and define the condition: currentView is not equal to 1 (currentView ≠ 1). And as formatting, select the option Read-only. Do the same for the other fields in the view 1 and 2.
9. For the View 3, we don't need to change it for every field, we can simple go to the Views Tab, select View 3, click on View Properties and select the option Read-only, for the entire view, because it's a simple summary view, not used to input data. In my form I also removed the borders of the fields.
10. Now the form is ready to use! But because of security issues with the C# code running on the form, we can't just publish it to SharePoint. We need to publish it as a separated template and then upload it to the server, in order to have a trusted template. The publishing process is the same, we only need to check the Web-form option.
11. After saving the file, we need to go to the central administration, and upload the form template. On the Central Administration, go to Application Management> InfoPath Form Services> Manage Form Templates. Simply select the file to upload.
12. After uploading, we need to activate this form in a Site Collection. To do it, click on the form on the forms list, and select the option Activate to a Site Collection. On the next screen, simple select the desired site collection and click in ok. When we finish this step, the form will be available in the Form Templates library of the main site of the selected site collection.
13. Now we need to select this template as the template of the Library. First, go to the Form Templates Library on the Site and copy the shortcut to the Template. In my case the URL is something like: http://mysite/FormServerTemplates/Steps.xsn. Then, go to the InfoPath Steps library, and on the menu, select Settings> Form Library Settings.
14. On the settings, click on Advanced Settings and change the option Allow managed content types to Yes, and also the option Display as a Web page, under Opening browser-enabled documents. Just click in Ok after the changes. With this configuration, the forms will open directly on the browser, and we will be able to manipulate our content type.
15. Now, on the Settings screen, click on the content type Form, to go to list settings. Click on Advanced Settings, and on the document template, paste the Form Template URL and click in Ok. Back on the Settings screen, click on the Current View field, and select it as hidden. This way, the user can't modify this field using the edit forms option, just the workflow will handle it.
16. Finally it's time to create the workflow! On the Library create a new Workflow. The idea is to change the steps after a review of the user, so let's build the workflow this way. The first step is an Update an item, to change the currentView field value to 2.
17. After the Update, let's use a Request Review action (it can be other action as well) to send an email to the user, asking to check the form. The configuration is simple, just select the initiator as a Reviewer.
18. The last step is to change view to the summary. So, simply add an Update an item, to change the currentView field value to 3. After that, let's to Settings> Startup Options and select to Start when items are created. After saving, Publish the workflow.
19. Finally the workflow can be tested. Go to the Library, create a new form and save it. You will see that it's impossible to modify the data in a different view from the current one, and also on the summary view. Have fun!
20. You can hide the Views on the Form Options. Click Tools > Form Options and uncheck the checkbox Views. Publish the form again and that's it, only the code behind changes the form view.