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
My Drupal sites:
Hi thanks for this just what
Hi thanks for this just what i was looking for,
One issue the data being sent back to field-last-mention [node:title] is being displayed as [node:title] not the actual title, any clues to fix this?
How to do that, if the
How to do that, if the reference field is a multi value field?
Hi @sg88, all! This is
Hi @sg88, all! This is exactly what I'm trying to do right now: to handle multi-value field (entity reference). I'm not getting the fields of that referenced entity in the list of fields available to update. How do I do that, please?
I'm also trying to do this,
I'm also trying to do this, in handle multi-value entity reference fields. Did anyone here find a solution?
Many thanks for the great example.
Hi, same problem with a multi
Hi, same problem with a multi-value entity.
Somebody above finded a solution ?
Any solutions?
Any solutions?
Sadly, this scheme simply
Sadly, this scheme simply does NOT work for me!!! I do wish Drupal.org would invoke some standards to remove such erroneous information from the site. I've wasted countless hours chasing phantoms down rabbit holes such as this one.
Jake