2

What I try to achieve with Rules:

After saving a new comment, this comment has to be sent only to those users who've checked a corresponding boolean box on their profile page.

Any suggestions?

2

Assuming your question is about D7, there are basically 2 ways (options) to answer your question, as further detailed below.

Option 1: Use Rules and Views Bulk Operations

You could create a view (using the Views module) of those users that you want to send an eMail to.

After you succeeded in creating such view, you can process the results of a VBO enabled view via Rules, using a rule that looks like so:

  • Rules Event: After saving a new comment.
  • Rules Actions:
    • Load the VBO list of the users in your View.
    • Add a loop to perform a Rules Action "Send an eMail", for each user contained in your Views results.

For more details, have a look at the tutorial "How to process the results of a VBO enabled view via Rules?".

Option 2: Use Rules and Views Rules

a) About this module

The Views Rules module makes Views data available in Rules, enabling intuitive rule configuration for dynamic data. Some details from its project page:

... provides two types of elements in Rules, configured with a "Rules" view display:

  • Views loop: A views loop is similar to a regular Rules loop, but allows looping over rows of view results.

    enter image description here

  • Collect view result rows (action): This action collects each variable in all view result rows into list variables for use in Rules.

Tip: When selecting the data type for variables in the view, if the field is an entity identifier (e.g. Node ID), you can set the data type to the entity type (i.e. Node) to directly use the variable in Rules as an entity!

b) Create a view of display type 'Rules'

After you enable the Views Rules module, you can use Views to create a view of those users that you want to send an eMail to. Add of view of display type Rules (important, that's the key to make it work!). Here is how you can add such display:

enter image description here

Next configure the row variables, by using the link that says "edit field info", as shown here:

enter image description here

You probably want to use one or more of the variables similar to those that are shown in this screenprint:

enter image description here

c) Create a rule using the view of display type 'Rules'

Create a rule that looks like so:

  • Rules Event: After saving a new comment.
  • Rules Actions:
    • Use the link that says Add view loop to add a Views loop, and select the "Rules" display created in the previous step.
    • Configure the parameters and variable names.
    • For each user contained in your Views loop, perform a Rules Action "Send an eMail", using the variables you configured at the end of the previous step (you may have to revisit the previous step to add more similar variables there if needed). If you created the Rules row variables as suggested in the previous step, your actual eMail can use tokens such as [usermail:value], [username:value], etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.