Last updated November 9, 2012. Created by lyricnz on November 9, 2012.
Log in to edit this page.
Let's say you're creating a node, and that node type contains a field which is a reference to another node. Whenever a node is created, you want to update the referenced node with some piece of information from the node that was just created. Here's a Rules recipe for that:
- create a node type "Referenced Node", with a text field that will ultimately be updated by the rule (called "last mention")
- create a node type "Trigger Type", which contains an entity reference field (called "the other one")
- create a rule "After saving new content":
- add a condition: Content is of type node+triggertype on the [node] (that was just created)
- add a condition: Content is of type node+referencednode on the [node:field-the-other-one] (the reference field in the node)
- add an action: Set data value, [node:field-the-other-one:field-last-mention] to "He said: [node:title]". This looks through through the reference in the node that was created to the referenced node, and into a field on that node. The reason that Rules knows about the field is because we added the second condition above!

Tested by:
- create a referenced_node: title=ReferencedNodeA, LastMentioned=Nobody
- created a trigger_node: title=TriggerNodeA, TheOtherOne==>ReferencedNodeA
- confirmed that rule executed (debugging on), and that the referenced node had it's LastMentioned changed to: "He said: TriggerNodeA"
The rule export is attached below.
| Attachment | Size |
|---|---|
| 9:11:12 10:33 AM.png | 128.55 KB |
| rules-referenced-node-update.txt | 666 bytes |
Comments
Massive thanks lyricnz
Massive thanks lyricnz
Some of my Drupal sites: