2

I want to create a rule that sends an email when a user has points for a particular category that reaches a certain value, e.g., 100. Having problems with the condition. I have a User Points category = Contest.

Rule Event: User was awarded points

1st Condition: Data Comparison Data to compare: [userpoints-transaction:tid], Data value: Contest

2nd Condition: i) Tried, Data Comparison, userpoints-transaction:points, equals, 100

ii) Tried, Data Comparison, userpoints-transaction, but not correct option as the value to compare doesn't allow an integer

Action: Send mail, I have email, subject and message.

With just the 1st condition, the Rule works, I get an email when someone gets a point for the Contest category, not for other categories.

Can't figure out a condition so that will send an email when someone reaches 100 Contest User Points.

Anyone done this? Thanks

0

Perhaps you can use the patch that's provided here: https://drupal.org/node/1109992.

  • Thanks so much Jeroen. That was just what I needed. Works perfectly. – danielesus Nov 28 '13 at 10:32
  • I'm glad it helped. You can mark my answer as the solution to help me in return if you want. :) – Jeroen Nov 28 '13 at 13:59
0

As an alternative to using the patch mentioned in the previous answer, you may want to use another approach, as detailed below ...

Indeed, there is no Rules Condition to check a user's current userpoints balance. However, have a look at this Rules example (in Rules export format):

{ "rules_display_userpoints_after_updating_content" : {
    "LABEL" : "Display userpoints after updating content",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "userpoints_rules", "rules", "rules_conditional" ],
    "ON" : { "node_update" : [] },
    "DO" : [
      { "userpoints_rules_get_current_points" : {
          "USING" : { "user" : [ "site:current-user" ], "tid" : "all" },
          "PROVIDE" : { "loaded_points" : { "total_points" : "Number of points in all categories together" } }
        }
      },
      { "drupal_message" : { "message" : "You now have [total-points:value] points" } },
      { "CONDITIONAL" : [
          {
            "IF" : { "NOT data_is" : { "data" : [ "total-points" ], "op" : "\u003C", "value" : "100" } },
            "DO" : [
              { "drupal_message" : { "message" : "You have sufficient points (you have [total-points:value] ...)." } }
            ]
          },
          { "ELSE" : [
              { "drupal_message" : { "message" : "You DO NOT have sufficient points (you only have [total-points:value] ...)." } }
            ]
          }
        ]
      }
    ]
  }
}

It does retrieve, as the very first Rules Action (not Rules Condition!) the current amount of user points of a user. If the amount is at least 100, it will display a message starting with "You have sufficient points ...", otherwise the message starts with "You DO NOT have sufficient points ...". It should be straight forward to adapt the display of the message to a corresponding Rules Action to send an eMail.

The example applies for "all categories" together. If you want to limit it to just a single category, just change it to the tid of the desired category (like 0, or 1, etc).

In this example I'm using the Conditional Rules module. As an alternative to using this module, you can also create corresponding Rules Components, with similar Rules Actions to be performed, but also with additional Rules Conditions equivalent to any Rules Conditions you'd want to include by using the Conditional Rules module. And then perform that Rules Component inside your Rules Actions of your original rule. For more details on that, refer to the answer to "What's the alternative to using the Conditional Rules module?"

So the clue to make this rule work is the very first Rules Action "Load user points of a user".

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

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.