1

I have a rule that is triggered on the event After updating an existing user account. The rule performs an action, Set a data value, that changes one of the values of the user account fields.

However, doing this causes the user account to be saved again, which triggers After updating an existing user account a second time. This causes some of my other rules that are triggered after updating a user account (such as those for sending notification e-mails) to be triggered twice.

I know this Set a data value rule is the issue because when I disable it, the account is only sent once, and the other rules that send notifications only send a single notification.

Is there a way to avoid this (single) recursion when setting a data value with a rule?

4 Answers 4

2

Your question seems like a variation of the question 'Why is my rule that reacts on event "After updating an existing user account" firing twice?'. The accepted answer in that question might help to understand your issue (what's causing it) also, ie:

some other module code is calling a user_save on hook_user_update triggering the rules event a second time.

That question also has another answer with a very interesting workaround, with an image which looks like so (a picture is worth more then 1000 words):

enter image description here

0

As per my understanding you need Rules Conditional module. We can run loops in rules action as well as we can put OR, AND conditions.

So at one time you can run loop for multiple actions which can solve your problem but you will have to workaround.

Edited texts --

You can set a field in profile with display hidden status. Name as per your like e.g. - WORKFLOW.

Use a taxonomy vocab for this field value where you add action names which you perform. If you have multiple action which need to be performed only once then set this field to have multiple value.

When you perform some action which need to perform only once, add one more action relevant to this action & for which a term is available in vocab such as "mailsent","sms-sent" etc..

Now go to the condition and add one more condition where you have to check whether that particular field WORKFLOW doesn't have this value.

So when once your mail action is performed, it will add a value "mailsent" & next time your condition will deny proceeding this rules s it will get "mailsent" in the field value..

I hope it helps..

10
  • My issue is that running the action Set a data value on the user profile causes the event After updating an existing user account to be performed again. How does this module help with that problem? Jun 26, 2013 at 7:01
  • You can run the same action in the loop when you are performing some more action such as sending email etc..
    – RajeevK
    Jun 26, 2013 at 7:06
  • I don't want to run the same action multiple times. Instead, I want the event After updating an existing user account to only be evaluated once. Jun 26, 2013 at 7:14
  • @PatrickKenny As per my understanding & experience with rules, it doesn't invoke some hook, so that other action get performed again. You need to combine your all action at one place which ever you want to perform, or use some field as condition in other rules which you don't want to be performed if you have such field like those which you are updating again..
    – RajeevK
    Jun 26, 2013 at 7:19
  • @PatrickKenny - I have edited my answer & added one workaround solution, which may help you.
    – RajeevK
    Jun 26, 2013 at 7:42
0

This is not an ideal solution, but I just manually coded the necessary Set a data value behaviors in PHP in a custom module; this prevents the other rules from being triggered twice.

8
  • Did you try the solution which I gave you ? That works fine as I tried with different kind of event "Checkout complete" where I was setting value & it worked as I have gave example..
    – RajeevK
    Jun 26, 2013 at 14:50
  • No, your solution will not work because this problem is specific to the After updating an existing user account event. Jun 26, 2013 at 14:58
  • It will work. You just have to add one more hidden field in profile & set a data value when your rule work. And check the same value in condition when the rules get executed...
    – RajeevK
    Jun 26, 2013 at 15:00
  • I also need some way to unset the value then, because the rules need to be called every time the account is saved. Jun 26, 2013 at 15:02
  • Why do you need to unset? You set value in that rule only which you want to be executed once & check the value in same. Other rule which has to be executed again & again won't set any value neither it will check..
    – RajeevK
    Jun 26, 2013 at 15:04
0

You shouldn't worry about the fact that the Rule is triggered twice. If you activate debugging at Workflow > Rules > Settings, a grey box ("Rules evaluation log") appears when a Rule is run. In your case, you'll see that the same Rule is triggered two times. However, the second time the following message appears:

Not evaluating reaction rule YOUR RULE to prevent recursion.

This proves that Rules is quite a smart module. :)

1
  • If it shows the rule is not evaluated, then it's not triggered twice. I am aware of this feature, and it's great, but in my case the rule was actually getting evaluated twice (circumventing the feature), which is a big problem. Aug 6, 2014 at 5:47

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.