1

I created a view which is a list of comments made by users to a particular node.

I then created a rule which triggers upon event "when a new comment is saved" The action is to load the view i created, loop through the list and then send an email to all the users who have previously posted comments.

My challenge is that it sends emails to the users based on the number of times they appear in the list. So for example a user who has made 3 comments to the node will get three (3) emails each time a new comment is saved.

I have tried using the Distinct query. It did not work. I also installed the Views distinct module and selected the filter option. This filtered the list to one value each, but mails were still sent multiple times to people who had commented more than once.

Please is there a way to ensure emails are sent only once irrespective of times user has commented to the node/appears on the list?

  • you could try turning on aggregation - I have found this solves similar problems - distinct shouldn't do anything, since it is actually retrieving distinct records. If memory serves, add a relationship to comment author, then a field to comment author uid, aggregate on the UID, COUNT – Geoff May 21 '15 at 5:15
0

You can adapt my answer with a "trick filed" on your content type in this (last) answer. Update "trick field" when your mail is sent the first time. Why is my rule that reacts on event "After updating an existing user account" firing twice? Then hide "trick field" modifying your "form-id" and field name with this solution (2nd answer) Is there a way to prevent a user from seeing a field on their user profile page?

0

I suggest you rework this part of the Rules logic you tried:

I then created a rule which triggers upon event "when a new comment is saved" The action is to load the view i created, loop through the list and then send an email to all the users who have previously posted comments.

Here is a blueprint to actually do so:

  • Create a new variable, which you define as a "list of users" (so that you can use this list later on to "loop through the list", as in the quoted text above).
  • Replace that "send an eMail" (within your existing Rules loop) by an action to "Add an item to a list" (using the list you created via that new variable). When doing so, you make sure to set "ENFORCE UNIQUENESS" to true, so that you "only add the item to the list if it is not yet contained" (see where I'm going?).
  • After the Rules loop is finished, the value of the new variable will contain a list of unique users. So just add another Rules loop at the end, to iterate of each of the users in that list. And guess what you can then do in this additional Rules loop ... indeed: send an email to each of those users, similar to what you already have in the rule you tried. The difference being that now each user is only contained 1 time in that list, so they will only receive 1 eMail.

Easy, no?

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.