1

I'm working on a Drupal project where users can post classified ads. These are simply nodes created using a custom content type.

After 3 months, we want the user who created the node to receive a reminder email. We also need this email to be sent only once.

We're using Rules to send the emails.

This seems simple enough, but the implementation has been very difficult.

Right now, I'm stuck at limiting the number of times the email is sent. I have spent considerable time and effort online trying to find the answer. I still haven't found a straightforward explanation for this task. The closest I've seen is on this forum, which is why I'm asking for your help. It would be greatly appreciated.

= The setup =

There is a "Classified Ad" content type. It includes an "Email" field, and a (hidden) "Email sent?" field.

The user creates a "Classified Ad" node.

Views lists every ad that is more than 3 months old. The View has a VBO field. It also lists the "Email sent?" and "Sticky" values.

The "Send email" Rule is activated when the Cron runs. It has no conditions. It currently has three actions:

  • Load a list of entity objects from a VBO View. (This loads my list of 3 month old ads.)

  • Loop. (Loads the VBO list.)

    -- Send HTML e-mail. (Sends email to the "Email" field value).

That works. So far so good.

My idea from here would be to add an action in the loop which would change the value of the "Email sent?" field from 0 to 1. I would then filter my View to hide all nodes that have this value.

= The issue =

I can't make Rules loop through my View and change the field value. I know others have had comparable problems and I've tried to apply the suggested answers but I didn't have any success.

I have also tried changing the Sticky value, but no success there either. I can change the first VBO item (at least for some tests), but I can't make Rules loop through all the items to update my nodes.

I have tried various approaches. The latest and (it seems) most promising is to use the Views Rules module. I installed it, created my "Rules" display for my VBO list, and added the Views loop to my Rule.

From there I tested all the combinations of Actions and Data Selectors I could think of to change the field value, but still no success. There were many tests.

Adding a "Set a data value" action inside my Views Rule Loop using "field-email-sent" as Data selector seems the most logical, but then Rules asks for a second Data selector, which makes no sense. When switching to direct input mode, I have to pick a "Node identifier", which makes even less sense. Attempts with other Actions or Data selectors have yielded similar results.

So either my approach is wrong, or one/more of my parameters are wrong. Either way, I need help.

How do I make this work?

1

You could use the Flag module to get this to work, by configuring an appropriate (non-global) flag, which you should then use to (automagically) flag a user after such user was emailed for the first time. To actually flag such users, you should just improve the Rule you use to send those emails, by adding a rules action to flag that user with the flag you created.

Any time your existing rule is about to send another email, you can then verify if it is the very first time, or yet another time. For this verification, all you'd have to do is use a Rules Condition to check "has this user yes or no been flagged already (with the flag you created for this purpose)?".

If you're not familiar with the Flag module, checkout either of these:

PS: I'm assuming this is about D7 ...

  • Yes, this is D7. I'll try out the approach you suggest and post the results here. – cmaltais Dec 1 '18 at 19:29
0

The Flag module was indeed the perfect solution.

Flagging users would not have worked, since users can post multiple ads.

However, flagging the node works great. Very easy to set up in Rules also.

I then added a relationship in my view to the flag, which allowed me to add a "flagged" filter. Now only unflagged items will receive the email, which is what the client needed.

Thanks again!


P.s.: Using Flags was a much better way to go in this case, but I'm still not sure if it's possible to loop through a VBO list and change a field value. The question seems to come up from time to time, so if anyone has an answer it could be useful to post it here for future users.

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.