Hi,

My objective is to update an existing message which is displayed on my site's "activity feed" to include the names of all users that comment on the node if the comment occured within 1 hr of the last comment. This is to avoid multiple messages saying user x,y,z has commented on a node. I have looked through posts like node/1538736 for a solution but none of the ones I saw address how to do this via rules. I am using rules for creation of all of my messages for my different message types and then views to render.

So I created a message type and added fields:
Node reference field_node_ref
Published field_published
Comment author reference field_comment_author_reference

field_comment_author_reference is multi-value to accept and ultimately display the list of commenters. My issue is understanding how to build this using rules. Creating a message and setting the data values for my message type fields is understood. To update an existing message, I assume I have to fetch a message id. So I set my action to:

Fetch entity by id
Parameter: Entity type: Message, Identifier: [comment:node:nid]
Provides variables: Fetched entity (entity_fetched_1)

However, when I use actions to set my message type field: field_comment_author_reference, it doesn't show up in the data selector. I am not sure if I am just not doing this the correct way or if the functionality doesn't exist in rules to be able to do this. I am not looking to do this in code via extra module.

If anyone can provide specifics about how to do something like this using rules or if someone can export their rule, that would be awesome as I am sure others would benefit from more details around this more advanced functionality in Drupal.

Thank you!!

Comments

niallmurphy-ie’s picture

I'm very late here but this general tip may help others.

The trick is to use two rules.
Rule 1. Load the list of messages, loop through them and force save them.
Rule 2. A rule for Event: Message updated. In this rule, you have access to the fields.

You might need something like https://www.drupal.org/project/rules_session_vars to store data like nid between the two rules if necessary.

bluegeek9’s picture

Status: Active » Closed (outdated)