Posted by mlittle on February 27, 2010 at 11:00pm
I have a node with a date field. For this discussion let's assume that the value in the date field is 1/1/2010. I would like to check all the nodes (of a particular content type) and, once that date is equal to or greater then x number of days from today, send an email to someone. Obviously, each node would have a different date as populated at the time the node was created. I want to iterate through the nodes and if the node date is equal to or greater then x number of days from today, do something like send an email. Is this possible with rules or do I need to do something with cron, or both.
Thanks for your help
Comments
Rules or Rules + VBO
Hya
What you describe should be a good case for Rules.
I see two ways of doing it:
1) You use Rules Scheduler (included in the Rules project) to schedule an e-mail when each node is created. I haven't tried it myself, but it should be possible to use a CCK date field and add (say) 20 days to it. The actual e-mailing is done on a cron run, but Rules takes care of queueing all the e-mails to be sent.
2) The other way is to use Views Bulk Operations, and list all the nodes that match the date criteria you want. Then you can use Rules to run the VBO once every day (or so). Sending e-mail with VBO is pretty straight forward, but it becomes trickier when trying to configure the VBO fields through Rules.
The first solution is good if you want one e-mail per node. The second is good if you want one e-mail per day, and each node can occur in several of them. Either way you will have use of Rules Scheduler.
Some more comments:
* The first solution could send repeated e-mails, but it will probably be trickier than the second one.
* If you use the first one you should make Rules keep track of queued e-mail and change them whenever dates are changed in the nodes.
* The second one will be tricky. Sending e-mails with VBO is pretty straight forward, but configuring VBO fields through Rules is not.
I just wrote a blog post on making Rules and Views Bulk Operations work together: http://nodeone.se/drupal-planet/make-rules-dance-with-views-bulk-operations. It might be some help if you want to get started on that track.
Good luck!
//Johan Falk, NodeOne, Sweden
Just so I understand...
Johan,
First, thanks for the reply and the information. Are you suggesting that, when the node is created to queue the email and just have it wait until the predetermined date? Just for clarification... My site has date fields in the my node (created with cck). The date is always in the past, about 3 months prior. Basically it's the date of an event that happened in court. Each node would most likely have a different date, although it is possible that some could have the same date. I need to send someone an email 160 days after that date. So, say the node is created today and that date field has 1/1/2010 in it. I need the email to be sent on 6/10/2010 (160 days later). Are you suggesting to just create the email when the node is created and hold it until 06/10/2010? And this could be done with rules and cron? If I understand your response, I believe the first solution matches my requirements the best.
Thanks again for your help.
Mike
You got it all right!
If that is your needs, then solution one is the right way to go. One node, one e-mail.
The procedure to create the function you're looking for is roughly as follows:
Save. Try it out.
If you want to go further, consider adding functionality to adjust the scheduled e-mail if the date changes. That would require a new rule set (delete-old-and-make-new-scheduling) and a new triggered rule (activate-on-content-changed).
You might also want to spend some time thinking about edge cases, such as someone typing a date three years ago. Should it send an e-mail right away, or none at all?
That's it, I think.
Rules, Rules Scheduler, Token. And cron.
Good luck!
//Johan Falk, NodeOne, Sweden
PS: If step 5 turns out to be difficult you might want to add another CCK field and have it automatically set to the previous date field + 160 days. It could be done with Computed Field, but also with Rules if you activate the forms support. Using the value in the new field for scheduling would be easy.
They have some solution here.
They have some solution here. http://groups.drupal.org/node/21377