This is part of a series of posts about some InfoPath tips and tricks. It’s not an introductory tutorial and will assume that you have some knowledge of InfoPath. All solutions will use InfoPath 2010 with SharePoint 2010.
A really useful feature in InfoPath is the ability to create multiple views within a single form. These can be used for two key benefits:
- Display a different view when the form is opened – useful for automating processes e.g. after a new form has been submitted, a reviewer opens the same form but sees a Reviewers view with different fields available to edit.
- Break a form into smaller chunks by switching views whilst the form is open – useful for easier viewing amongst other things…
Create a new view
With a form open in InfoPath 2010 Designer, click on the Page Design tab in the menu. On the left of the menu is a Views section. Here you can set the properties for the current view, delete it and create a New View. (Page Setup just opens the Properties with the Page Setup tab instead of the General tab).
If you want to create a new view, click New View…
Within Properties for the current view, there are some useful settings worth considering.
On the General tab, a box is checked ‘Show on the View menu when filling out this form’. If you want to control what view a person can see during the process (e.g. when filling out a new form, you don’t want people to also complete the Reviewer’s section) then uncheck this box. If it is checked, it will be visible in a dropdown menu (unless the View menu itself is disabled – more on that in a separate post).
Under Print Settings, you can control which view appears when a user goes to print the form. This is a great little feature. Create a dedicated ‘Print’ view, and then for all other views, configure the Print Settings to open the Print view. For the Print view itself, under General set it to be Read-only.
Finally, make sure you pick carefully which form is to be the default view. In the absence of any criteria saying otherwise, this will be the view that opens. In most cases, this should be the ‘New Form’ view, since it will be the view that opens when someone goes to create a new form.
Display a different view when the form is opened
You should want the ‘new form’ view to be displayed when a new form is created. But once it has been saved and submitted to a library in SharePoint, you may want a different view to then be displayed for editing or for specific stages of a process.
To do this, you need a criteria to determine what stage the form is at. I tend to use a ‘formStatus’ field that is updated based on what the user does with the form. The value of the formStatus field then determines which view is opened. Here’s how:
Step 1: Create and manage a formStatus field
Create a field called formStatus, of data type Text (note: this field doesn’t need to be added to the form, it can be created direct in the Fields list). Set the default value for the field as New.
Add a Button control to your page. For its properties, make the label ‘Submit…’ (or similar), leave the Action set to Rules and Custom Code and click OK.
Single click on the button and the Rules taskpane should appear on the right of the page. If it doesn’t, in the Home menu, click on Manage Rules (you must have the button selected to create a rule for it).
- In the Rules task pane, click New and select Action
- Give the rule a title (Details), e.g. ‘Update Form Status to Submitted’
- You don’t need to set a condition, the rule will run when the button is clicked
- Next to actions, click Add and select ‘Set a field’s value’
- In the Rule Details dialogue box, for the field, select your formStatus field, and for the value, type ‘Submitted’ and click OK
Now, when a user creates a new form, it will start with a formStatus of New. When the user clicks to submit the form, the formStatus will be updated to Submitted.
Step 2: Configure the form to switch views when it is opened
We can now control which view of a form is opened based on the formStatus field. Note: this requires having at least two views already configured, for example: New Form (Default) and Review Form with additional fields for a reviewer to complete.
In InfoPath, click on the Data tab to display the Data Menu. To the far right of the menu is a section called Rules. Click on Form Load. This is a special rule for controlling what happens when the form is opened (or ‘loaded’ into memory, hence the geeky label).
- In the Rules task pane, make sure the title shows as Form Load. Click the New button and select Action (its the only option available to use)
- Provide a title (Details for) the rule, call it something like ‘Open Review View for Submitted forms’
- Set the condition to be where formStatus is equal to Subitted.
- Next to Run these actions, click Add and select Switch views.
- In the Rule Details dialogue box, select the view you want to be opened when the formStatus is Submitted. Click OK
In the image above, you can see the rules I have created for the Form Load. For completeness, I recommend creating a rule to open the New Form view. Yes this will be opened by default, but I like to cover all possibilities. As long as you manage that formStatus field, you can be certain which form view will open at any time during the process.
Switch views whilst the form is still open
As well as controlling which view is displayed when the form is opened, we can switch views whilst still in the form. This is recommended if you have a large form – break it into chunks. You can do more than just switch views at each stage…
If you choose to have the views displayed in the View menu, the user can pick any view at any time. You might not want to let them do that. A more manageable method is to make switching views part of filling out the form. At the end of each view, add a button to proceed to the next view (and go back to the previous one if you want to).
Step 1: Add a button to your form
On the Home menu, in the Controls box add a Button control or, if you want to make it even more obvious, add a Picture Button control and use arrows instead.
In the image above, I have added a Picture Button control and selected my home made Arrow picture. See end of the post for a tip on creating your own.
Step 2: Add a rule for when the button (or Picture button) is clicked
Make sure your button is selected (has the square handles displayed around it) and open the Rules taskpane if it isn’t currently showing (on the Home menu, click Manage Rules)
In the Rules taskpane
- Click the New button and select Action
- Provide a title (Details for) and give is a useful name, e.g. Switch to View 2
- You don’t need to set a condition, you want this rule to run whenever the button is clicked.
- Next to Run these actions, click Add and select Switch Views
- In the Rule Details dialogue box, select the view you want to switch to and click OK
And hey presto, we can now switch views as part of completing the form. The image belows shows my form in Design mode with the rule configured.
—
How to create that arrow? If you want a simple DIY cheat to create images for Picture buttons, open PowerPoint. Within PowerPoint, create the image you want. Then right click and choose Save as Picture…
In the image above, in PowerPoint I simply inserted an arrow from the Shapes available in the Insert menu (Illustrations section), added a bit of text, removed the chunky line around it, then right-clicked and saved as a picture. Then in InfoPath, open the properties of your Picture button and select your image.
And that’s all for now. Some tips for using views in forms.
All good forms should have more than one view. As a simple rule of thumb, if you only need one view, you don’t need a Forms library, you should just use a standard SharePoint list and modify the form that comes with the list (it’s a ready-made InfoPath form) which is far quicker and easier to do.
Click Here to view other InfoPath posts in this series.