1

I have a boolean field called verified defined in profile2. When this field changes from not ticked to ticked I would like to send out an email to the user. Easy I thought with rules

Starting using "After updating an existing profile" then comparing the fields profile2-unchanged:user:profile-directory-information:field-verified and profile2:user:profile-directory-information:field-verified (bascially saying equal and then negating the condition)

   "IF" : [
      { "user_has_role" : {
          "account" : [ "profile2:user" ],
          "roles" : { "value" : { "12" : "12" } }
        }
      },
      { "user_has_role" : {
          "account" : [ "site:current-user" ],
          "roles" : { "value" : { "3" : "3", "28" : "28" } },
          "operation" : "OR"
        }
      },
      { "NOT data_is" : {
          "data" : [ "profile2-unchanged:user:profile-directory-information:field-verified" ],
          "value" : [ "profile2:user:profile-directory-information:field-verified" ]
        }
      }
    ],

However they are always the same value and the rule never fires. However when I take out the condition and send myself an email with the two values. One is true the other one is false.

also tried this in the condition:

  { "data_is" : {
      "data" : [ "profile2-unchanged:user:profile-directory-information:field-verified" ],
      "value" : 0
    }
  },
  { "data_is" : {
      "data" : [ "profile2:user:profile-directory-information:field-verified" ],
      "value" : 1
    }
  }

which is also not working. Tried to move it in before saving a profile, and also in various save user events. Always the same result. So why are the values different in Actions then they are in conditions?

Am I missing something here?

2
  • Profiles are created only when needed. A user gets a profile after she successfully submits the profile form, or if it is specifically created in code. You must check for the existence of the profile first, or else you can create an empty profile for a user upon registration. Aug 15, 2014 at 19:18
  • That makes sense however it doesn't explain the behaviour. In this case the profile exists already. What I have found though if I take the second example if I only check for the unchanged value, it correctly recognises the correct value of the field. Also if I only check for the new value it recognises the correct value. It is only when I use both fields (either in one condition or seperate conditions) that both unchanged and new value are the same. Currently thinking of using a second boolean field to get over this limitation. Aug 16, 2014 at 5:45

1 Answer 1

0

Rule refinements

Entity has field

Make sure to add a Rules condition Entity has field (related to your additional profile2:user:profile-directory-information:field-verified-field in your Rules condition). And make sure to add that Entity has field condition BEFORE the condition you already have.

For a video tutorial that illustrates the importance of this Entity has field condition, refer to Data types and data selection, especially what is shown between about 13:30 and 17:30 in it.

Add ":value" to your fields

Adapt your rule by adding :value to both of your fields, so that they look like so:

  • profile2-unchanged:user:profile-directory-information:field-verified:value
  • profile2:user:profile-directory-information:field-verified:value

Rules debugging

If none of the above helps, then move on to Rules debugging, as explained in my answer to "How can I display the value of a variable inside a condition?".

Depending on what the result of that type of debugging is, you may also want to (temporary) enable the Devel module, so that you can (temporary) add a Rules Action like "Display a value" (in your case of your profile2:user:profile-directory-information:field-verified).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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