I'm trying to set up some Rules that schedule the execution of some component rules at a future date, but I want the day they get executed to be variable depending on the value of a field present in the node which triggers the scheduler rule.

Is there any way to have the offset for rules scheduler dates be dependent on a variable or value, rather than just hard coded?

Having it be hard coded means I'll have to create a rule for every permutation of the offset, which is rather tedious.

Thanks!

Comments

JeremyM-1’s picture

I would also like to know if this is possible with minimal coding.

spovlot’s picture

You can create a Rule Set Component to set a Date variable that can then later be used in the Scheduler rule. You can select entity fields or variables in the Scheduler rule for the execution date.
The Rule Set may have several condition/action rules to check the field you mentioned and set the variable to a certain date.

How will you field determine the offset specifically?

JeremyM-1’s picture

Thank you! I have a separate node with a duration field in it (in minutes) - Basically I want the date to be offset based on this field in a separate node that a user can set.

Possible?

spovlot’s picture

Sure. How will you reference the separate node? Do you have a reference field?

You can use the action "Fetch an entity by id" to load the content node. Then you can reference the node in subsequent actions.

Then you can use the action "Calculate a value" to add the duration to an existing date field.

mErilainen’s picture

How to calculate a value? I have amount of days as duration field which I want to use with a date field, but I cannot use the "Calculate a value" action, because it will only let me "add" two dates together, whatever it means. If I switch to direct input mode, I cannot use the data selector to get the value from the duration field.

PetarB’s picture

Just incase anyone lands here searching for a solution to this issue.

There is a Drupal 7 module for this:

https://www.drupal.org/project/rules_reldate