2

I'm using the Rules Scheduler (sub-module of the Rules module) to schedule an email reminder based on a date field set in the content type. So a user can request a reminder email on a specific date, to update that content.

However, if I invoke the Rules Action on node update, then I end up with lots of emails scheduled for that date.

How can I make sure that the rule is only scheduled once for the given date?

2

The answer to this is simple.

In the action of the rule that calls the schedule component evaluation, in the Identifier section, set a unique value, such as: reminder-[node:title]-[node:nid]

This value will be a unique identifier of the scheduled task. Scheduled tasks with the same ID will simply be replaced. Problem solved.

  • It is OK for your scenario. But there will be situations, like I face now, need to check if that scheduled task really exists. – Junaid May 25 '16 at 8:40
  • @Junaid : I'd be interested in more details about such situations that you were facing. Can you add some more details? – Pierre.Vriens Sep 5 '16 at 9:07
0

My answer to "Rule to store user's last post date and scheduled rule based 30 day reminder" contains an illustration about how to delete scheduled tasks, using the "schedule_delete": the schedule_delete that is part of this rule is to ensure that previously "scheduled" reminders will get removed when updating the data field (so that it only triggers 1 reminder, and with the most recent date).

Here is a copy of the Rules Action included in that answer (which refers to the Rules Component that is also included in that answer):

..
        "DO" : [
          { "schedule_delete" : {
              "component" : "rules_send_email_notification",
              "task" : "[account:name]"
            }
          },
          { "data_set" : { "data" : [ "account:field-next-article" ], "value" : "+30 day" } },
          { "schedule" : {
              "component" : "rules_send_email_notification",
              "date" : {
                "select" : "account:field-next-article",
                "date_offset" : { "value" : 2592000 }
              },
              "identifier" : "[account:name]",
              "param_user_to_notify" : [ "account" ]
            }
          }
        ]
...

What is crucial in the context of this question here, is that you have to ensure that you give enough thought to the value you'll use for the identifier of the scheduled task.

In my sample the choice was that for each user, at any time, there can only be 1 scheduled task for each user. So using the account name as the key for that identifier is perfect ... to make it unique, and to know exactly which scheduled task should be deleted also.

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.