Is there a difference between using AND in Rules Conditions and simply adding Rules Conditions one after the other?
Preface: I'm assuming this question is about D7 ...
Correction to the prior answer
I'm sorry, but the prior answer is only partially correct (which is the same as saying partially wrong, n'est-çe pas). Please allow me to briefly correct that (before anybody believes it):
- The question is about (contains) "... using AND in rules conditions ...", while the Conditional Rules module cannot be used in Rules Conditions (only in Rules Actions). Actually Rules Actions are the reason-to-exist for this (interesting) module.
- If you want to do something more complex, then you can ALSO use Rules Components as an alternative. So "You can only do that with conditional rules" is not true.
To AND and/or to OR?
Moving on now to the actual question, this is my answer to it:
This question is a typical Rules newbie question. Since it isn't obvious that within the Rules Conditions there are 3 ways to combine conditions:
- add an explicit "OR", so that either condition must be true (for the Rules Actions to be executed).
- add an explicit "AND", so that both conditions must be true (for the Rules Actions to be executed).
- do not add an "OR" or an "AND": that's equivalent to an explicit "AND".
One might ask then
So when do I ever really need to add an "AND"?The answer to that is if you need to more complex logic like in this sample:
Condition 1 OR (Condition 2 AND Condition 3)
In plain English: the Rules Actions will be triggered if either (or both) of these conditions are true:
- Condition 1.
- Condition 2 AND Condition 3.
Rules Conditions inside Rules Actions
But, the real Rules fun starts when this (typical) question arises: "I need to add something like a Rules Condition inside the Rules Actions, how can I do that?" ( * ).
To resolve this typical question, there are basically 2 approaches (that I am aware of):
- Use the Conditional Rules module. For an example using the Conditional Rules module (for which there is not a lot of docu available), refer to my answer to the question "How to prevent a node being saved when using the Rules module?".
Rework the relevant part of your Rules Action(s) into performing a Rules Component. Because in a Rules Component, it is possible to also add Rules Conditions.
Typical scenario: "Use Rules to perform a redirect for users with at least X user points, after some Rules Event Y happened". To get this to work:
- Create a Rules Component, with number of userpoints as a parameter. Within this Rules Component, add a Rules Condition (there you are!) to check if the parameter is at least X and add a Rules Action to perform the redirect.
- Create a rule, triggered when Rules Event Y happened. Retrieve the nr of user points for the current user (How to???). And add a Rules Action to invoke the previous Rules Component.
( * ): There are dozens of samples that are variations of this question, my favorite one is when some Rules Action needs to happen based on the number of User Points the current user has (and you do not like to use PHP as a Rules Condition, like I do). If you don't see why that's a variation of it, then first try to find out what the Rules Condition for that would be ... hint: it's a Rules Action, not a Rules Condition.