Thursday, February 28, 2013

Introduction to InfoPath rules


Rules allow you to control the behavior of a form by performing actions that take place based on conditions within the form, or events that take place when filling out a form. The behavior that you can control by using rules in a form includes automatically displaying a message inside of a dialog box, setting a field value, querying or submitting data to SharePoint or a database, or switching views. These rules can be triggered by the user changing the value in a control, clicking a button, or opening or submitting the form. They can also be triggered based on conditions that are present when the form is opened, such as the user role or based on a value that is queried from a data source.

Types of rules

The following three types of rules are available:
  • Validation    Validation rules are used to indicate an error when the user enters an invalid value into a control. For example, a validation rule on a text box can confirm that a user enters a valid e-mail address. For more information regarding validation rules, see Add rules for data validation.
  • Formatting    Formatting rules are used to apply text formatting and background shading to controls when a condition has been met. They can also be used to hide or disable a control. For example, a formatting rule can hide or display follow-up questions based upon a user’s answer to a preceding question, instead of including instructions for the user to “skip to step X.” For more information regarding formatting rules, see Add rules for conditional formatting.
  • Actions    Actions are the most varied type of rule. Use these to switch views, set values in other fields, submit the form, or query for data. Actions are available depending on what you are trying to apply them to and whether you are building a browser form or an InfoPath Filler form. For more information regarding rules that perform other actions, see Add rules for performing other actions.


Create rules

There are two ways to add rules to your form. On Home or Control Properties tabs, in the Rules group, you can use either the Add Rule menu or click Manage Rules to open the Rules task pane.
On the Home tab, the Add Rule menu is the fastest and easiest way to add rules to your form. For example, it only takes four steps to add a rule to your form to validate dates.
  1. Select the date picker control.
  2. Click Add Rule.
  3. Click Is in the Future.
  4. Click Show Validation Error.
Now, when a user enters a date that is in the future, an error message appears. You can customize this automatically-created rule using the Rules task pane. For example, you can make changes to the ScreenTip box to give the user a more specific error message.


Manage rules that are applied to controls

All rules are managed through the Rules task pane. Only the rules that are applied to the selected control appear. For example, if you have a text control with a rule applied to it that verifies user input is a valid e-mail address, only that rule appears in the Rules task pane when you select that text control.
Introduction to rules
You can use the Rules task pane to add, delete, or copy rules. For example, if your team gauges workload and risk on a sliding scale from 1 to 10, you can create a rule that flags a value of more than 7 by shading the field red, and then copy the rule to both the Team Workload and Team Risk fields on a form.
The following are some of the actions available from the Rules task pane:
  • To create a new rule, click New.
  • To delete a rule, select the rule, and then click Delete.
  • To copy a rule or all rules that are applied to a control, click Copy Rule or Copy All Rules.
  • To paste a rule that you have copied from another control, click Paste Rule.


Set rules for opening or submitting the form

Additional rules can be configured to run when the form is first loaded or when a user submits the form. To add form load or form submit rules, on the Data tab, in the Rules group, click either Form Load to set a rule that runs when the form is loaded or click Form Submit to set a rule for when the user submits the form. Clicking either Form Load or Form Submit changes what appears in the Rules task pane, in the same way selecting a control does. When you click Form Load, the rules that run when the form is loaded appear in the Rules task pane, where you can add or manage them as you require.
To enable the Form Submit button, do the following:
  1. On the Data tab, in the Submit Form group, click Submit Options.
  2. Select the Allow users to submit this form check box, and then click Perform custom action using Rules.
  3. Click OK.
 IMPORTANT    When the Rules task pane appears, create a new rule that runs when the form is submitted. If this is not done immediately, you must re-enable the Form Submit button. After a rule is added, the Form Submitbutton remains enabled, and then you can switch between different rule contexts.


Rule Inspector (view all rules in a form template)

Use the Rule Inspector dialog box to view all rules and calculated default values that are in use on a form. To open the Rule Inspector dialog, on the Data tab, in the Rules group, click Rule Inspector.
Introduction to rules
The Rule Inspector dialog box displays fields that have rules associated with them and how these rules are related to other fields in the form template. This also helps you to determine if there is a problem with the rules on the form and to resolve problems.
 NOTE    The Rules Inspector dialog box doesn’t display formatting rules.
When you open the Rule Inspector dialog box, four types of rules appear:
  • Validation
  • Calculated Default Values
  • Actions
  • Programming
Within each of these sections, fields that have rules attached appear, in addition to the rules for each field. For each rule, conditions and corresponding actions appear.
If you click on a field, the Rule Inspector displays the rules that are associated with that field, either directly or indirectly, in the following categories:
  • Rules that depend on this field or group    This category includes any rules that use the value in the field or group. For example, you can create a rule that runs when a user opens this form and the value in field1 is within a certain range.
  • Rules that are triggered by a change in this field or group    This category includes any rules that are activated if the value in the field or group changes. For example, you can create a rule that adds seven days to a user-entered date and automatically displays the new date in another control.
  • Rules that may change this field or group    This category includes any rules that can change the value of this field or group. For example, you can create a rule that sets the value of this field based on the value of another field in the form template.

No comments:

Post a Comment