This is a question I see in the forums occasionally, and is something that can be confusing for beginners - so I wanted to do a quick rule review.
Action rules in InfoPath fire when the field they are on changes. So let's look at the following scenario:
- You have a field called "Location"
- You want to set a field called "Phone" based on the selected Location
There are several ways you could do this, depending on the structure of your form and your secondary data sources. For example, if Location is a dropdown that is populated from a secondary data source, and you can associate Location to Phone with that data source, you may want to use a default value for the Phone field.
But you could also use a rule on the Location field to set the value of the Phone field. That rule will fire every time the Location field changes (as long as any conditions are met, of course!)
So - let's say the location changes from My Office to Your Office. If we have a rule on the Location field to set the Phone field, the rule will fire.
If the location changes from Your Office to blank, the rule will fire.
If the location doesn't change, the rule won't fire. (I know, you think I'm stating the obvious - but if you are using helper fields for some logic, and have some rule that sets the field to "true" and then never set it back.... you may be continually setting the field to the same value and not seeing why your rule isn't firing!)
If the rule is on the phone field, and you change the location, the rule won't fire. I think the confusion here often stems from the rule conditions - novice form designers may think that because a field in the condition changes, the rule will fire. This is not the case - the rule must go on the field that will be changing.
You can also use default values when you have secondary data sources with the information you need to populate - but be careful! Defaults can auto update, which doesn't always make sense - take the following scenario:
- You have an Order form. When the user selects the item, the price field is populated.
- If you set the price with a rule (using a value from a secondary data source) that value will be stable - unless the item is changed the price won't change.
- If you set the price with a default, and the secondary data source changes, the price could change when the form is re-opened. That's no good, right? When the item was selected, the price was $20. Now, three months later, the order has shipped, accounting re-opens the form and the price changes to $25. Accounting will hunt you down and shout at you.
I've got a simple sample form here that might help with the general concepts. Download the file, right click from the downloaded location, select Design to open in Design mode. From there you can preview and try it out!