3

I would like to send an email everyday that has a list of nodes that are filtered by certain conditions. I think the Rules module would be a good place to start.

Real Example:

  • Content Type named "Issue".
  • Field inside Issue that connects a user as Responsible Party for the issue.
  • Field inside Issue that defines it as either "Active" or "Resolved".
  • Email a list to the responsible party of their Issues that have a "Active" status.

If this can be done with Rules, what event do you have it react to? I would guess the core functionality of it would be put in a component that rescheduled itself every 24 hours. Then the action of the component would be "Send Mail". How would it grab the list of nodes that fulfill the conditions?

6
  • Yes it could do that. This question is not a very good fit for this site though as it currently is because it doesn't ask anything more specific than can rules do this, which it can. Is there something specific about the creation of this rule that you are having trouble with?
    – rooby
    Jan 25, 2016 at 5:41
  • @rooby Yes I am struggling to get this to work. My main concern is how it grabs the list of nodes. I added my specific struggles with Rules in the question.
    – KyleRiggen
    Jan 25, 2016 at 5:55
  • 2
    You need to use Views (and VBO I think) to get the result, then iterate over it sending the mail. It can be done in Rules. Without Views it will be a pain. There are lots of tutorials available about the integration of Views in Rules. Jan 25, 2016 at 6:16
  • yes, use views and filter the view by your Active. Then use rules to send your View by mail.
    – No Sssweat
    Jan 25, 2016 at 6:27
  • @J.Reynolds great thank you I'll find those tutorials
    – KyleRiggen
    Jan 25, 2016 at 6:33

2 Answers 2

3

When you want to run a rule periodically, use the event Cron maintenance tasks are performed.

This will trigger your rule whenever cron runs.

See the cron documentation on drupal.org for more information on cron and its configuration.

Because this action doesn't specifically involve nodes, the next problem is loading the nodes you want to act on.

How you do that depends on which nodes you want to load the nodes. Examples are (there are likely also other ways):

  • The Load a list of entity objects from a VBO View action that is provided by the Views Bulk Operations module. This was you can set up a view that lists the nodes you want to target and load the nodes from that list.
  • The Fetch entity by property action. This could be used to fetch all content of a given content type.

When you have a list of entities you can loop add a loop to your actions to loop through the list and perform actions on each entity.

If you need to check perform conditions as you are looping through (like checking the value of a field on the entities) you can use the Conditional Rules module to add if blocks.

2
  • Sorry rooby, I think there is a minor issue with this answer. Refer to the answer I added for details. Apart from that, this is a great answer (please don't delete it ...)! Aug 17, 2016 at 14:39
  • Good point. Haha, don't worry I won't delete this one. It's not as wrong as the other one I deleted.
    – rooby
    Aug 17, 2016 at 21:46
1

The previous answer (from rooby) is great, except that there is 1 thing I think that it is missing: the original question is about "every day": if cron runs multiple times a day (like every hour?), then you get multiple eMails. That's why I think the Rules Event Cron maintenance tasks are performed is not the most appropriate event. Instead I would use the "Rules Once per Day" module for that. Here is how it works (as per the comment in issue 2495775, from the module owner):

  • You specify a trigger hour on the administration settings page for this module.
  • The Rule trigger will then run when cron tasks are first run after the start of that hour. The actual run time will depend on your cron task timings.

So this is another way to understand/Read this:

  • The "Event" will only be triggered when a cron job is run.
  • And that event will only be triggered 1 time / day, i.e. "next time cron runs after the trigger hour has passed".

With that, you should be able to adapt your "rule that sends an email" to run ... once a day.

2
  • 1
    There are also some alternatives, eg. you could use drupal.org/project/rules_condition_site_variable and have a variable for when it last ran, then check that variable with a rules condition. This would be useful if you also wanted to interact with that variable with custom code.
    – rooby
    Aug 17, 2016 at 21:48
  • @rooby Wow, yet another Rules related hidden gem! Merci for sharing! Aug 18, 2016 at 5:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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