I'm trying to check if a date field value has been changed on a node update. (Rules Drupal 7)
Here's my rule configuration:
{ "rules_node_update" : {
"LABEL" : "Update",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules" ],
"ON" : { "node_presave--expedient" : { "bundle" : "expedient" } },
"IF" : [
{ "entity_has_field" : { "entity" : [ "node-unchanged" ], "field" : "field_tria" } },
{ "NOT data_is" : {
"data" : [ "node-unchanged:field-tria" ],
"value" : [ "node:field-tria" ]
}
}
],
"DO" : [ { "drupal_message" : { "message" : "UPDATED DATE" } } ]
}
}
Event: Before saving (i have already tried with node update)
NOT data comparison Parameter: Data to compare: [node:field-tria], Data value: [node-unchanged:field-tria]
What i'am trying to do here is... IF the (new) date value IS NOT EQUAL to unchanged field value (old)... THEN do something. (like print message on screen)
The result of the data comparison returns always TRUE and don't know why.
Notes:
- Having proven the suggested changes, the result remains the same. I edit a node, and whether I change the value of the "tria" field or not, it still returns true.
- If I (temporary) OMIT the data comparison it shows the final message. Here's an example of what i'm getting with my setup: Edit a node of this content type, the node already has a date data in the "tria" field. Without making any changes, just save. It shows the message. If i change that field value to another and then save. It also shows the message. So, i think node-unchanged value must me empty because she's not doing the data comparison the right way.
- Here is the debug of the variables after saving/updating a content : Debug value Parameter: Value to debug: [node-unchanged:field-tria] ... (Array, 1 element) 0 (Array, 6 elements) value (String, 19 characters ) 2001-01-10 01:00:00 value2 (String, 19 characters ) 2001-01-10 01:00:00 Debug value Parameter: Value to debug: [node:field-tria] ... (Array, 1 element) 0 (Array, 10 elements) value (String, 19 characters ) 2001-01-20 01:00:00 value2 (String, 19 characters ) 2001-01-20 01:00:00 Values are there, and they are different! as expected!
- The rule evaluation log shows this once the node has been updated with different values:
The rule evaluation log shows this once the node has been updated with no changes on the values... just saved
$day1 = $node->field_tria['und'][0]['value']; $day2 = $node_unchanged->field_tria['und'][0]['value']; if ($day1 != $day2) { return true; }