Rules - send email when users role changes to x I need to send an email when an admin changes a users role to role x. The email should not be sent if the users role is already role x and 'save' is pressed on the user page.

I have set up a rule:

Event: After updating an existing user account

Actions: Send mail

This works fine. Then I add a condition of type 'data comparison' account(updated user):roles with the operator 'equals' and the data value 'role x'. But for some reason the email now never sends when I change the user role to 'role x' and resave. I'm confused about why this is not working. 

Then once this is fixed I assume I'll need to negate the condition that the account(unchanged user):roles equals 'role x'
Arpitr got me on to the correct solution for this. Here is the code that you can import:

{ "rules_update_user_role" : {
"LABEL" : "Update User Role",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules" ],
"ON" : { "user_update" : [] },
"IF" : [
  { "user_has_role" : { "account" : [ "account" ], "roles" : { "value" : { "7" : "7" } } } },
  { "AND" : [
      { "NOT user_has_role" : {
          "account" : [ "account-unchanged" ],
          "roles" : { "value" : { "7" : "7" } }
        }
      }
    ]
  }
],
"DO" : [ { "drupal_message" : { "message" : "Changed User!" } } ]


}
}

I like the way arpitr used a drupal message for testing if the rule had worked - i didn't realise you could do this.

It looks like the mistake I might have been making was to use the condition of type 'data comparison' and then try to drill into it to get to the user role rather than just using the 'user has role' condition. I think when i had tried previously to use the 'user has role' condition it failed because I made the used 'account:roles' rather than just account.

Hope this helps someone else.