2

I have created a rule using the Rules UI. My rule is not working, and I need to debug it, displaying the values of my variables inside a condition where I make a comparison.

I see within Rules Actions that I can add a system message, but in condition how could I debug variable values?

Rules debug log doesn't show value of variables.

How can I do so?

3 Answers 3

1

You might have a combination of Rules Conditions that need some debugging. Rules is great, but sometimes also tough to debug if things don't work as you'd expect. There are some typical facilities to do such debugging (further detailed below), but a Keep-It-Super-Simple technique I often use, is my BINGO-trick. A sample of such rule can be found in my answer to "Which Rules condition can be used to email a user when an admin updates their profile?". Stupid, but simple and efficient (I think).

Also, if you have multiple Rules Conditions in a single rule, you should try to see what happens (if you get a "bingo") for each of the individual Rules Conditions. This by simply (temporary) removing 2 out of the 3 Rules Conditions you are using, and verify if they each result in the Rules Action you'd expect (also just a simple Bingo-message should be sufficient).

If the above doesn't help, then there are typically 2 ways of more advanced debugging, as further detailed below.

Rules Evaluation Log

Within the Rules settings, experiment a bit with the debugging facilities that come with the rules module. At least have a look at the "Rules Evaluation Log" (to check that the Rules logic being executed, actually matches what you expect that logic to be).

Here is an example of such Rules Evaluation Log:

enter image description here

Rules Action to display a value (using devel)

You may also want to (temporary) enable the Devel module, so that you can (temporary) add a Rules Action like "Display a value". That's not within Rules Conditions (as in your question), but if you add that as your first Rules Action, then you can be sure that the values displayed are identical to the value of these variables at the end of the Rules Conditions.

Obviously, make sure that there are no Rules Conditions that would prevent the rules Action(s) from being executed (if needed temporary remove such Rules Conditions).

Resources

1
  • sure @Pierre.Vriens, I am new in stackexchange and thank you for tell me how it works.
    – bunset
    Apr 26, 2016 at 21:17
2

Try cloning the rule, and adjust the clone, remove your condition & add a system message action that shows the two variable values you are trying to debug.

BTW, Eventually you may want to install a debugging environment like xdebug. This is likely a longer process than you'd want to tackle for a quick fix. However, if you are planning to keep working in the field, it's incredibly helpful.

You'll find a good start here: https://stackoverflow.com/questions/7303912/setting-up-xdebug-for-drupal-site

0
2

For debugging of rules in Drupal you can use ddebug_backtrace function but before use this function you have to install devel module (because ddebug_backtrace is dependent to this module). Please click here for more info.

1
  • I'm not familiar with this debugging approach for the Rules module, and would like to learn more about it. I also wonder how this relates to the Rules action "display a vlalue" that you also get from the Devel module. Maybe you can expand your answer a bit, eg with some links to relevant articles, docu, etc? PS: +1!!! Apr 29, 2016 at 9:54

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.