0

How can I set a reminder for a specific user to be triggered on a specific date (in a Drupal 7 site)?

Example: I want to remind the user regarding particular event such as hepB vaccination day.

Any suggestions?

3
  • See drupal.stackexchange.com/q/60785/16495 or drupal.stackexchange.com/q/74818/16495 or drupal.stackexchange.com/q/66643/16495 - and then please elaborate on what have you tried, what was the exact problem etc. Use linked questions as examples how to explain your needs in a way that makes them an answerable question.
    – Mołot
    Jul 27, 2015 at 10:10
  • How many hours or days in advance do you want that reminder to be created? 1 hour? 1 day? Something else? Jul 27, 2015 at 10:48
  • once in a month, well also to achieve this i tried to create rules but it throwing error as "Data selector site:current-user:roles: for parameter node is invalid".
    – rose
    Jul 27, 2015 at 10:52

3 Answers 3

3

Rules module

Use the Rules module together with Rules Scheduler (a sub-module of it), as explained in the 3 steps below. These steps are based on a date field which is added to the user profile, so that for each user you can indicate an appropriate date.

Step 1: Create a field to store the appointment date

Add a field to the "user" entity with machine name (say) field_next_appointment. Allow only 1 date (to store the "next" appointment), but don't make it required.

Step 2: Create a Rules "Component"

Here is the Rules Component to be created (in Rules export format, just import it in your own environment via copy-paste, which you can do using the "Import rule" link located at admin/config/workflow/rules):

{ "rules_send_email_notification" : {
    "LABEL" : "Send eMail notification",
    "PLUGIN" : "action set",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "USES VARIABLES" : { "user_to_notify" : { "label" : "User to be notified", "type" : "user" } },
    "ACTION SET" : [
      { "mail" : {
          "to" : [ "user-to-notify:mail" ],
          "subject" : "Friendly reminder about your upcoming event",
          "message" : "This is a reminder about the upcoming event that you have an upcoming event on [user-to-notify:field_next_appointment] ...",
          "from" : "[site:mail]",
          "language" : [ "" ]
        }
      }
    ]
  }
}

Obviously, the Subject and Content of the eMail may need review / tuning, while you might also want to use some other From eMail ID.

Step 3: Create a "Rule" using the Rules Component

Here is the Rule to be created, in Rules export format (just import it in your own environment via copy-paste, which you can do using the "Import rule" link located at admin/config/workflow/rules):

{ "rules_on_new_user_event_registration" : {
    "LABEL" : "On new user event registration",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "rules_scheduler" ],
    "ON" : { "user_update" : [] },
    "IF" : [
      { "entity_has_field" : { "entity" : [ "account" ], "field" : "field_next_appointment" } }
    ],
    "DO" : [
      { "schedule_delete" : {
          "component" : "rules_send_email_notification",
          "task" : "[account:name]"
        }
      },
      { "schedule" : {
          "component" : "rules_send_email_notification",
          "date" : {
            "select" : "account:field-next-appointment",
            "date_offset" : { "value" : 259200 }
          },
          "identifier" : "[account:name]",
          "param_user_to_notify" : [ "account" ]
        }
      }
    ]
  }
}

Note that the above rule refers to the Rules Component from the previous step.

Also note the machine name of field_next_appointment in this rule, which is the field's machine name created in Step 1 (if in step 1 you used another machine name, then also replace the machine name field_next_appointment in this rule with the machine name of the field created in Step 1 (if you don't have such field yet, or the field names don't match, then the import of the above rule might not work).

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).

Step 4: Further tuning and enhancements

  • The date_offset (=259200) in the above rule corresponds to "3 days in advance", which may need review / tuning.

  • If needed, you could also use the Field Permissions module to set field-level permissions to edit, view and create fields on any entity.

  • Instead of just sending an eMail (as in the Rules Component), you could replace that by a more advanced option using the Message module (which has great integrations with the Rules module also). Here is an quote about that module (from its project page):

    ... enables logging and displaying system events in a number of different use cases. Events that are recorded over time are sometimes call activity streams. Exportable messages subtypes can be created for different use cases with custom fields and display (view) modes.

Note: Using Rules to send an email X days after a user registers also contains quite some details that may help you.

Date Reminder module

There is also the Date Reminder module. Here is a quote about this module (from its project page, bold markup added here):

... allows a registered user to request an email reminder to be sent at a specified time before an event. Generally these would be calendar events, but any node type that has a CCK datetime can support reminders.

However I think that module is not going to answer your question, because:

  • it's the user who has to request such reminder (in your question you want to set a reminder to a specific user).
  • these reminders are related to some node, while your question is related to a user. You might possibly work around this by creating some extra node type (like "Appointment"?), though that seems like overhead.
6
  • What's the current status of this question? Did you have a chance to review my answer and experiment with it? If so what results did you get? Aug 27, 2015 at 5:15
  • Hi @pierre Vriens:actually i tried with what u suggested, since m a newbie following some tutorial i created a rule component i,e 1]i set component plugin as action set ,2]specified name and machine name with variables like *data type-date,*label-user *machine name-user.but i dint get to see option for import the code which u have specified.
    – rose
    Sep 2, 2015 at 9:23
  • and u have mentioned to create the user entity field, in the first step,but to store the date i have date field. i am i right?please correct me if am wrong.
    – rose
    Sep 2, 2015 at 9:28
  • in rules 1] click on new view 2]add the event, specified the name and react on :content expired 3]added the action->chosen the created component. this is what i have done . please correct me if i am wrong.
    – rose
    Sep 2, 2015 at 9:43
  • @rose : I slightly refined my answer her, to help you find the rules-import link. Also, if you have some other field with machine name (eg) like field_date_from_rose, then use that field instead of what I called "field_next_appointment". Let me know if this helps/works for your case. May 10, 2016 at 15:03
2

Using the Date Reminder module will be helpful for you. Some details about it (from its project page):

  • When reminders are enabled for a node, registered users (with the appropriate privilege) can request reminders to be sent before each occurrence of the date/time. The user specifies how long before the date/time to send the reminder.
  • When reminders are enabled for a node type, anyone who can edit the node can enable or disable reminders for that node.
  • Reminders are sent using the Messaging system. The usual reminder method is email, but other messaging transports should work. (Well, not Drupal 7. The Drupal 7 version just uses straight email.)
  • System administrator can control:
    • Which node types allow reminders, and which date field (if there are several) in a type to use as the basis of reminders.
    • Which (registered) users can request reminders.
    • Which users can request reminders to arbitrary email addresses instead of their own.
    • Which users can see or administer other users' reminders.
    • Content of reminder messages.
    • If and how long reminders should be kept after last date occurrence.
    • The list of allowed lead times for reminders from which users can select.

An effort is under way to move much of the documentation here to the Date Reminder section of the Site Builders Guide. Currently that document is very incomplete, but watch there. Information on this module page will gradually be moving there.

1
  • I have installed date reminder module and set the configure settings but I could not able to see option for Requesting a Reminder.
    – rose
    Jul 28, 2015 at 13:49
0

You can create a cron job to execute a specific task at a scheduled time, as explained also in the article Managing Cron Jobs with PHP.

Your Answer

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

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