2

I need a rule that checks if the value of a field has been changed by a particular role.

I created a rule with event "After updating existing content".

I added two conditions :

  • user has role :

Parameter: User: [site:current-user], Roles: Web Team

  • NOT data comparison :

Parameter: Data to compare: [node:body], Data value: [node-unchanged:body]

What I expect is to see the rule fired when a user with role "Web Team" changed the value of the body field of a node.

I expect the rule NOT to be fired when a user with role "Web Team" edit and save a node without changing anything.

And I expect the rule NOT to be fired when a user with no "Web Team" role edit and save a node.

But everytime the user with role "Web Team" edit and save a node, regardless if he changes something or not, the rule is fired.

I tried to change the event in "Before saving content" with no more success.

The log displayed after the save is the following :

0 ms Reacting on event Before saving content.
12.599 ms Evaluating conditions of rule test2. [edit]
19.604 ms The condition user_has_role evaluated to TRUE [edit]
23.194 ms The condition data_is evaluated to FALSE [edit]
23.23 ms AND evaluated to TRUE.

How AND can be evaluated to TRUE if one of its conditions is evaluated to FALSE?

I did many tests but really don't see how to solve that.

I hove somebody could help me.

Here is the rule exported :

{ "rules_test2" : {
    "LABEL" : "test2",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "workflow_rules" ],
    "ON" : { "node_presave" : [] },
    "IF" : [
      { "user_has_role" : {
          "account" : [ "site:current-user" ],
          "roles" : { "value" : { "5" : "5" } }
        }
      },
      { "NOT data_is" : { "data" : [ "node:body" ], "value" : [ "node-unchanged:body" ] } }
    ],
    "DO" : [
      { "workflow_rules_set_state" : {
          "node" : [ "node" ],
          "workflow_state" : { "value" : { "11" : "11" } },
          "workflow_comment" : "Title or body modified by webteam. The content should return to contributors for validation."
        }
      },
      { "drupal_message" : { "message" : "node-title = [node:title]\r\n\r\nnode-body = [node:body]\r\n\r\nnode-unchanged-title = [node-unchanged:title]\r\n\r\nnode-unchanged-body = [node-unchanged:body]\r\n" } }
    ]
  }
}

Best regards

1 Answer 1

5

You have to use :value for the body or other textarea fields.

The problem is there:

{ "NOT data_is" : { "data" : [ "node:body" ], "value" : [ "node-unchanged:body" ] } }

Should be:

{ "NOT data_is" : { "data" : [ "node:body:value" ], "value" : [ "node-unchanged:body:value" ] } }

Your Answer

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

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