I'm trying to add a time duration field value (integer type representing seconds) to a date field using rules, but I'm not able to reference the duration field when it comes time to calculate/edit the date value (presumably because they are of different field types). I can do things like "+30 days", but really what I want to do is "+$x days".
The interval module provides an action "Apply an interval to a date" (you find it in the "data"-section of the action list). The module supplies a "interval field", but surprisingly, instead of providing integration between rules and that field, it provides that action, which provides integration between rules and an integer field. The action allows you to specify a data value and specify which interval that number is to be interpreted as (days, months, ...)
Thanks to rosell.dk for pointing out the Interval module. Just to expand on that:
First create 2 conditions to check if the 2 fields exist.
Entity has field: entity1:field_number_of_days (Integer) Entity has field: entity2:field_date (Date)
Then you need to create TWO rules. First rule:
Apply an interval to a date: Interval Number: entity1:field_number_of_days Interval Period: days Date: entity2:field_date Provided Variables: new_date
However, you're not finished. This stores ( date_field + number_of_days_field ) in a new date value called
new_date. In order to save that new date back into
date_field you have to create one final rule:
Set a data value: Data: entity2:field_date Value: new_date
FYI I solved this by invoking a rules hook to change the field to duration. This solution was inspired by fago's commerce subscription products module.
I would also like to hear more information about this. I am trying to create a rule which follows up on existing orders of specific products. Each product has a different time interval for "follow up reminder", and my rule should trigger an email to be sent to a customer at a date which is calculated Order Creation Date + Follow Up Interval.
ie Order Creation + Value provided from Products in the order