2

Backstory: I have a content type that will send an email after a period of time if a boolean is true. From the creation of a node to the time the email will be sent, the boolean could change at any time.

My Problem: I would like a clean way to have the conditions of a rules (see if the boolean is true) to be evaluated before going about executing an action set. Through my testing, I cant get the Rule to be properly check the boolean when a node is both created and updated.

Optimally, I would like the conditions to be evaluated after the elapsed time of the Rules scheduler rather than upon initially after being created or updated.

Clarification Edit: Make a Rule that will execute sending an email after a given set of time that is set by the user upon node creation. The single condition of sending the email is if a boolean is true. The boolean could be modified on node creation or through a node update. So the Rule can not be activated based on one of those. No Sssweat was able to show me how to move an evaluation from a standard Rule to the component allowing it to only be evaluated when the standard Rule scheduled the component. So the Rule is set up to be triggered on node creation with only a given time frame field as its condition. Depending on which time frame field was selected, the Rules Scheduler will start. During this period the boolean to be evaluated could be shifted from true to false many times. So only be the end of the scheduled time should the boolean even become relevant. The component side of the rules looks at the boolean to see if it should send the email or not. If true > send email. If false > do nothing.

Some more clarifications:

  1. The user has a field to choose the time frame for resolving the node.
  2. If a node is updated, the countdown should not be reset. One email should be evaluated to be sent at the end of the given time frame.
  3. If the boolean has been changed to false, the email should not be sent and no further action is needed.
  • ugh, almost had it, problem with my answer is that it would only check after updating or creating, but fails as it won't send the e-mail if x time passes and the node does not get updated. – No Sssweat Dec 4 '15 at 12:53
  • Haha yes the same issues I have been having. – KyleRiggen Dec 4 '15 at 12:58
  • I haven't tested my new answer, but on paper it looks like it will work =) let me know how it goes. – No Sssweat Dec 4 '15 at 13:13
  • Sorry if this question was not clear enough. I have added information to help make it more understandable about what I was asking and how No Sssweat was able to help me out. – KyleRiggen Dec 13 '15 at 21:30
3

Give this a try

Create a New Component

1) Add Compotent of Rule.

2) For Data Type: select Node. Name, Label and Machine name use whatever you want.

3) Add condition of Content is of type

  • For Data Selector: put your Node Data Type machine name. Ex: if you gave the node data type a machine name of test you put test
  • Select your content type

4) Click on Add and select Data Comparison and select your boolean field.

Example: When creating the component, if you gave the Node Data Type a machine name of test and your boolean field is named hello. For your boolean field you need use test:field-hello as your data selector.

5) Add action of Send Mail.

Now Create a new Rule

1) For action use after content is created

2) Leave the condition empty (no need for condition here)

3) for Action add the scheduled component evaluation and select the component you just created.

  • use node as your data selector

I believe this will evaluate your rule component only when the schedule time hits.

  • 1
    revised my answer. – No Sssweat Dec 4 '15 at 13:24
  • Can a boolean that is a field of the content type be evaluated in a component? I don't think it can. – KyleRiggen Dec 4 '15 at 13:35
  • 1
    @KyleRiggen thanks for bringing that up, Updated my answer. Apparently you can, as long as you add a Content is of Type condition. – No Sssweat Dec 4 '15 at 14:04
  • 1
    Since you accepted the answer, I take it you figured it out. You just needed the Node data type, no need to add any other data types. – No Sssweat Dec 5 '15 at 2:04
  • 1
    using node should work, because that's what you are passing to your component, the node you just created. – No Sssweat Dec 5 '15 at 3:16
0

The accepted answer to this question is indeed a solution for the question asked. Whereas a condensed version of the question is like "How to send an eMail after some predefined time after the creation of a node, provided some boolean is (still) true the moment that eMail should e triggered?".

I think you're making it too complicated by what you're asking for. To explain what I mean, first have a look at my answer to the question "How can I set a reminder for a specific user to be triggered on a specific date?". Obviously, that is not the same question as yours here. But the "specific date" there corresponds to your "predefined time after the node creation date".

With that, you could avoid that (not obvious to implement) validation if you'd just trigger another rule each time that the node is edited, and then verify the relevant data of your node content to decide if you need to do either of these:

  • no more need to send the eMail "later on", so just DELETE the scheduled execution of the Rule to send your eMail.
  • (re-)schedule the execution of the Rule to send your eMail.

Apart from the simplification of the Rules logic with this approach, you also get the advantage that the "queue" of actually scheduled eMails is always accurate (the scheduled rules correspond to nodes that have a current status that indicates that the eMail is still relevant). While with your current implementation (to validate again at the time the eMail is due), you may have zillions of scheduled rules that are sitting there, while at the very last minute it turns out many of them were just waiting to do .... nothing.

Bottomline: sometimes the solution for a problem is ... to avoid the problem from happening.

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.