Why Isn't My Rule Firing? - Hilary Stoupa

InfoPath Dev

Hilary Stoupa

Why Isn't My Rule Firing?

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:

  1. You have a field called "Location"
  2. 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:

  1. You have an Order form. When the user selects the item, the price field is populated.
  2. 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.
  3. 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!



Jacob Russ said:

This is not the case for hiding sections, correct?  In my experience, the rule in this case is placed on the Section, even though it is referring to another field as a condition.  Please correct me if I am mistaken - this is simply how I have seen it done, and have been doing it so far.

September 11, 2018 12:56 PM

Hilary Stoupa said:

Right - conditional formatting is different from action rules.

September 11, 2018 1:03 PM

About Hilary Stoupa

I wandered into development after working as a business process analyst for a global manufacturing company. I create InfoPath solutions for our clients as well as work as a developer on company tools that extend InfoPath. I've also been instrumental in creating the InfoPath Master Class training provided by Qdabra.

Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.