I want to use Rules UI to define some action sets, but want to execute those actions programmatically from a custom module.

How to I execute the action by code and pass the needed arguments (just a node in this case).


1 Answer 1


If you have set it up as a rules component, you can use rules_invoke_component, alternative you can invoke an event, which could trigger mutiple rules by using rules_invoke_event.

Both is similar in that you pass first a name/id and the rest of the args is passed along, so something like

 rules_invoke_component('name', $node);

if your custom component rule has several parameters pass them one by one and separate them with comma as example

rules_invoke_component('rules_save_search_send_activation_sms',  'paramval1', 'paramval2', ....);

is properly how you need to do it. This again depends on how the rule/component is defined and configured.

  • Thanks, that was exactly the function I was looking for. I had to pass the argument directly, though - probably because I just have one arg configured in the component. rules_invoke_component('rules_mycomponent', $node);
    – valderama
    Commented May 17, 2011 at 15:03
  • @valderama, great I updated my answer in case others need the same info.
    – googletorp
    Commented May 17, 2011 at 15:17
  • Does this work for drupal 6?
    – user2014
    Commented Jan 14, 2012 at 9:10
  • @landing Rules have changed a lot from 6 to 7, but rules_invoke_event exists in 6 rules_invoke_component does not, but I don't believe rules in 6 has the concept of components.
    – googletorp
    Commented Jan 14, 2012 at 9:25
  • if you have custom rule compoent ,pass parameters one by one and separate them with comma example rules_invoke_component('rules_save_search_send_activation_sms', 'test ', '93333333333');
    – Yuseferi
    Commented Aug 6, 2015 at 15:43

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.