4

I want to send an e-mail after a user profile is updated but not if they are only resetting their password.

I already have the rule working so that when the user profile is updated it sends the e-mail with all the user details, but rules recognises a password reset as an account update. I don't want an e-mail to be sent if it's only a password reset.

Neither of the below rules work as expected, the first one only fires if both fields are changed, if i change the first field but not the second I get this message in the log file "Unable to evaluate condition data_is." if I only modify the second one then I don't get the e-mail.

{ "rules_account_update_2" : {
    "LABEL" : "Account Update 2",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules" ],
    "ON" : [ "user_presave" ],
    "IF" : [
      { "NOT data_is" : {
          "data" : [ "account-unchanged:field-first-name" ],
          "value" : "[account:field-first-name]"
        }
      },
      { "NOT data_is" : {
          "data" : [ "account-unchanged:field-last-name" ],
          "value" : [ "account:field-last-name" ]
        }
      }
    ],
    "DO" : [
      { "mail" : {
          "to" : "",
          "subject" : "",
          "message" : "",
          "from" : "",
          "language" : [ "" ]
        }
      }
    ]
  }
}

The rule with an OR condition, this just never fires no matter what fields I change.

{ "rules_account_update_2" : {
    "LABEL" : "Account Update 2",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules" ],
    "ON" : [ "user_presave" ],
    "IF" : [
      { "NOT data_is" : {
          "data" : [ "account-unchanged:field-first-name" ],
          "value" : "[account:field-first-name]"
        }
      },
      { "OR" : [  ] },
      { "NOT data_is" : {
          "data" : [ "account-unchanged:field-last-name" ],
          "value" : [ "account:field-last-name" ]
        }
      }
    ],
    "DO" : [
      { "mail" : {
          "to" : "",
          "subject" : "",
          "message" : "",
          "from" : "",
          "language" : [ "" ]
        }
      }
    ]
  }
}
  • 1
    The problem is that the password property isn't exposed to rules. You are either going to have to code something for rules to use or use the conditions in rules to compare the before and after of all of the other profile fields. Make sure your event is "before saving user account" so you can compare the values of the profile fields – Nigel Waters Aug 30 '13 at 18:14
  • This is the way I'm going to go, first attempt has failed so far though, I'm doing a data comparison on unchanged-field and field which seems to work with one field but if I add and or condition and then repeat the same rule condition with a different field it doesn't seem to work – Daniel Harper Sep 2 '13 at 12:14
  • Don't use and/or. Just add all of your "has fields". Then compare. – Nigel Waters Sep 2 '13 at 13:25
  • a single condition comparing fields unchanged vs new, or a condition for each field but without the OR? – Daniel Harper Sep 2 '13 at 14:07
  • a condition for each field but without the OR – Nigel Waters Sep 2 '13 at 14:14
1

1st rule

About your 1st rule, for which you wrote in your question this:

Neither of the below rules work as expected, the first one only fires if both fields are changed

Sorry to say, but the Rules module is working as designed ... because within your Rules Conditions, you basically specified that BOTH conditions must be satisfied.

Actually you did not specify an AND or an OR, and therefor the 2 Rules Conditions are combined with the default operator ... which is AND.

2nd rule

About your 2nd rule, for which you wrote in your question this:

The rule with an OR condition, this just never fires no matter what fields I change.

Sorry to say (again), but the Rules module is working as designed ... because within your Rules Conditions, you basically specified that 3 conditions must ALL be satisfied, i.e.:

  1. Field "first name" must be changed, AND
  2. Some "empty" OR construction must be TRUE (as is shown with the line in your exported rule that looks like { "OR" : [ ] }, ... there is nothing between the [ ] in it), AND
  3. Field "last name" must be changed.

Your crucial error is within that 2nd condition: you started to add on "OR" construction, but you didn't specify the 2 conditions for which that "OR" should be used. You probably thought that Rules Condition 1 and 3 are the 2 conditions to be combined with that "OR", but that is not how the Rules syntax is like (confusing, I know, many users struggle with this ...).

Therefor, try this variation of your rule (and don't forget to complete the Rules Action to actually send that eMail):

{ "rules_account_update_2" : {
    "LABEL" : "Account Update 2",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules" ],
    "ON" : [ "user_presave" ],
    "IF" : [
      { "OR" : [ 
          { "NOT data_is" : {
              "data" : [ "account-unchanged:field-first-name" ],
              "value" : "[account:field-first-name]"
            }
          },
          { "NOT data_is" : {
              "data" : [ "account-unchanged:field-last-name" ],
              "value" : [ "account:field-last-name" ]
            }
          }
        ]
      }
    ],
    "DO" : [
      { "mail" : {
          "to" : "",
          "subject" : "",
          "message" : "",
          "from" : "",
          "language" : [ "" ]
        }
      }
    ]
  }
}

Note the difference here: this rule has 1 Rules Condition, which is an "OR"-construct, and 2 (sub) Conditions to be combined with that "OR" are your 2 Rules Conditions about first name and last name.

BTW, when debugging / developing Rules with a Rules Action to send an eMail, I always (temporary) replace such Rules Action with just a "display a message" (like "It works! Just rework the display of this message now to sending an eMail").

PS: I'm assuming this question is about D7.

0

Best solution: You should make use of profile2 module and make the profile separate. so you can create separate rules for entity update and user update.

other possible solution: if you have very few profile fields, make a before saving user event rule and add a rules AND condition to compare all profile field data with old data so you can know whether profile has changed or not.

  • you can add the conditions on rules action section by using rules_conditional module.
  • 1
    seems over kill as I only have a few fields on the profile – Daniel Harper Aug 30 '13 at 14:20
  • IMO the the Conditional Rules module is in no way going to help to resolve the issue described in the question ... because that module is used for Rues Actions, whiile the question here is about Rules Conditions. – Pierre.Vriens Aug 16 '17 at 21:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.