I have two content type "foo" and "bar". When I update a "foo" node I need to get two values from foo's fields (cck integer and node reference) and update a cck filed in the referenced node of type "bar".

But I have a problem: $node and $node_unchanged have the same values.

I have tried the token version: "[node:field_costo_importo-raw]" and "[node_unchanged:field_costo_importo-raw]". But I have the same result: both have the same value.

M.

CommentFileSizeAuthor
#6 screenshot1.png14.22 KBcbop

Comments

Elementica’s picture

Title: $node and $node_unchanged have the same values » even on D7
Version: 6.x-1.4 » 7.x-2.0-rc1
Component: Rules Core » Rules Engine

I think #1283148: Unchanged, updated and saved content all equals for field collection in "Before saving" and "After updating existing" content is just the same problem.

It's driving me crazy a little bit... I'm trying everything but with no hope at all. I just can't get the unchanged value in any way of custom fields. Maybe could also be related to #1167328: Rules integration: [node_unchanged:field_XXXXX] returns updated node content but I've tried the trick (show message with both tokens) and it doesn't work for me.

For my work I'd need at least a temporary solution to retrieve the unchanged value... any idea is welcome!

---

Going on I've tested that in my case only "field_collections" rise the problem... maybe something related to the fact that changing items in collection doesn't change the container itself, so references are overwritten. That is:

node:

  • nid
  • title
  • ...
  • field collection (element 1):
    • field a
    • field b
  • ...

  • changing values of fields "a" and "b" doesn't change "element 1" of collection, but only its content and old values are lost... maybe.

lomo’s picture

Title: even on D7 » $node and $node_unchanged have the same values

Reverted issue title to original since "even on D7" is not a descriptive issue summary for people browsing the queue. ;-)

Elementica’s picture

Version: 7.x-2.0-rc1 » 7.x-2.0

Nothing yet... after a while I'm back to this problem again... I've just (today) downloaded latest core and revisions of modules (I've updated versione reference in issue settings to 7.x-2.0) and the bug si still there. Any idea is welcome!

SilviaT’s picture

Same problem here: I'm trying to trigger an action when an existing node is published (but not every time it's updated and published at the same time) and I'd like to use the node-unchanged:status value in the rule conditions, but it seems it doesn't affect the event triggering.

Glenmoore’s picture

Same again. I need to check that a field has been changed and so I am doing a data comparison but it's coming up TRUE every time.

cbop’s picture

StatusFileSize
new14.22 KB

I'm getting slightly different behavior than described here -- but also the wrong behavior. I'm trying to update the 'created' time-stamp whenever an unpublished article is then published. So, I first created a rule for "Before saving content", which has two conditions: (1) node:status == 'Published ' AND (2) node-unchanged:status == 'Unpublished'. But this never works. In fact, in no case can I get it to update the timestamp when publishing (or unpublishing).

But when I reverse the values, and check for node:status == "Unpublished", and node-unchanged:status == "Published" (exactly the opposite of what I want), it works as I want it to -- when publishing a previously unpublished article. (See attached screenshot of this rule which works).

But this is treating node-unchanged:status and node-status as precisely the *opposite* of what I can only suppose they mean. Shouldn't [node-unchanged:status] contain the value *before* being saved; and [node:status], etc., the *new* values? But they are not behaving that way. But neither are they merely switched, because the opposite values simply never results in any update. This is frustrating. What's up?

cbop’s picture

Update: I found a work-around for my situation -- "Content is published" on [node] and NOT "Content is published" one [node-unchanged] does the trick.

For some reason Data comparisons on node:status and node-unchanged:status are not behaving correctly, but "Content is published" on the respective nodes does work. Strange.

rbrownell’s picture

Component: Rules Engine » Rules Core
Status: Active » Needs work
subhojit777’s picture

Issue summary: View changes

I am not sure whether this is an issue. As pointed out in #6, if I use "Before saving content" it is working; and not working for "After updating existing content". May be we are not reading it right and this is how it works.

kandrupaler’s picture

For the problem described by @cbop, what's working for me is the following:

NOT Content is published on [node]
NOT Content is published on [node-unchanged]

If I check for these two conditions (no and or or blocks added), the condition section evaluates to a TRUE for nodes which have never been published before. And then I can go ahead and change the created timestamp.

Note: If I check only one of the above, the condition section evaluates to a FALSE for nodes which have never been published before.

tr’s picture

Status: Needs work » Postponed (maintainer needs more info)

I don't know exactly what everyone was trying (no one posted an export of their rule, most people didn't even mention what event they were using), or whether their use cases are still a problem in the existing version of Rules, but I have tried some simple rules and I can't reproduce this. Specifically, it's not true in general that "$node and $node_unchanged have the same values", although it may be true in certain specific cases that I didn't test because of the missing details about how to reproduce this error.

Regardless, here's an export of one of my test rules. This rule reacts on the "After updating existing content" event and compares the node:title to node-unchanged:title to show a system message if the title has changed. After saving this rule, if I edit only the node body I do NOT see a message, but if I edit the node title I DO see the message. So it works properly, as far as I can tell, and node does have different values than node_unchanged.

Perhaps it was fixed by the two related issues mentioned in #1: #1283148: Unchanged, updated and saved content all equals for field collection in "Before saving" and "After updating existing" content or #1167328: Rules integration: [node_unchanged:field_XXXXX] returns updated node content. (If you look into those, you will see those were resolved years ago by certain other fixes in Rules...). But if this is still a problem for you in the current version of Rules then please export your problem rule, show your work, and explain how to reproduce the problem.

{ "rules_node_vs_node_unchanged" : {
    "LABEL" : "Node vs. Node-Unchanged",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "rules_i18n" ],
    "ON" : { "node_update" : [] },
    "IF" : [
      { "NOT data_is" : { "data" : [ "node:title" ], "value" : [ "node-unchanged:title" ] } }
    ],
    "DO" : [ { "drupal_message" : { "message" : "Title was changed" } } ]
  }
}
tr’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)