4

I have a node type called event.

An event has a "Event Date" date field, and a "Staff" user reference field.

I need to send a reminder emails to all referenced users, 1 day before the event date to remind them they are working.

I'm getting lost in Rules trying to work out what actions I need it to react on, and how to get the users emails to send the message to.

My problem is pretty similar to "How to send notification for an event for users that have signed up with the list of events for that month?" which was asked 3 years ago and didn't get a reply.

Can someone who is an expert with rules help me out?

UPDATE:

I have it working for one user reference field now. Added relationship "User: Duty Manager (field_duty_manager) - reverse" and contextual filter "(field_duty_manager) Content: Nid" with "Hide view" when filter is not available. I can type in "55" into the perview, and it only lists the Duty Manager, perfect.

My next struggle is to get this to work for the mulitple user reference fields. Am i going to have to clone the rules for each individual field?

enter image description here

1 Answer 1

4

I will show you how to do it when a new event is created. You must in addition provide for when an event is updated (by deleting the scheduled event and rescheduling it) and when an event is deleted (by deleting the scheduled event). If an event does not exist and you delete it it won't throw an error, so it is acceptable to do it.

You need the following additional modules installed: Views and Views Bulk Operations, reason being you will use views to obtain the list of emails and VBO is needed to interface it with Rules.

STEP 1 Start by adding a view (don't select page or block in wizard as we only want a master) of type 'Users'. Remove the sort and pager as it is not necessary.

Add a relationship 'A bridge to the Content entity that is referencing User via field_staff' and make it required.

Add a contextual filter of nid: 'The node ID.', make sure the relationship created earlier is selected, and Hide view when filter value is not available.

Add a field 'Bulk operations: User' and accept the default. This is the important field and technically the only field needed.

Test the view by typing a known node id in the preview field.

STEP 2 Create a Rules component of type 'Action Set' and call it 'Send Notification'. Add a Variable of 'Entity: Node', give it a label and machine name of 'node'.

Add an action to this component: 'Load a list of entity object from a VBO View'. Select the view you created earlier. Set its argument to '[node:nid]' and leave the provide variables at default. Note the variable name of the List of entities: entity_list.

Add a loop to this action, and select 'entity-list' as the Data Selector. Note the default name of the current list item: list_item.

Add an action to the loop (note: add it to the loop and not the component) of 'System: Send Mail'. In the to value select '[list-item:mail]'. Fill the rest out the way you want.

STEP 3 Add a new rule and call it 'On new event', to react on 'Node: After saving new content'. Restrict it to type 'event'.

Add an action to this rule, 'Rules schduler: schedule component evaluation', and select the 'send notification' component you created earlier.

Set the evaluation date to node:field-event-date.

Add an offset: -1 days

Add an identifier of 'node-[node:nid]-event' and note its pattern as you will be using it to delete events.

Select the Node as 'node'

That should be the gist of it.

7
  • Incredible. Thank you so much. I knew it was there somewhere, but I would never have worked that out on my own! I have tested it, and a schedule is created perfectly one day before the event date. With your help, adding the delete and re-schedule rules was easy as well. Amazing answer, thank you!
    – Collins
    Oct 31, 2014 at 11:25
  • Actually, the schedule creation, delete etc is perfect. The bit im struggling with is the view. I actually have 5 user reference fields, one for manager, one for bar stewards etc. I cant find the relationship you mention "A bridge to the Content entity that is referencing User via field_staff" - I can only see relationships like "User: Bar Stewards (field_bar_stewards) - reverse". Not sure what the "reverse" means?
    – Collins
    Oct 31, 2014 at 12:38
  • You said you have a staff reference field on the event type. I assumed it was a multi-value field. The relationship in the view is created from the user (the base table) back to the event, but as the staff reference field points from the event to the users, we have to add a reverse relationship, ie a bridge to the Content entity that is referencing User via field_staff'. We then add a contextual filer of node:nid on the view to restrict the result to users referenced from a specific event. The rule passes the nid of the event to the view which returns only the users referenced in the event. Oct 31, 2014 at 12:58
  • OK i have added the reverse relationships, and nid contextual filters for each staff field. These user reference fields are multi value. I cant get any results to show though, please see my updated question for the screenshot
    – Collins
    Oct 31, 2014 at 13:09
  • I have it working for one user reference field now. Added relationship "User: Duty Manager (field_duty_manager) - reverse" and contextual filter "(field_duty_manager) Content: Nid" with "Hide view" when filter is not available. Thank you for your help. My next struggle is to get this to work for the mulitple user reference fields. Am i going to have to clone the rules for each individual field?
    – Collins
    Oct 31, 2014 at 13:24

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.