Maybe Im missing something, but this is extremely frustrating.
I am trying to schedule an action based on the value of a field for a node. This was a simple task in drupal 6. Now i need a data selector but the schedule form only seems to take fields that are formatted as a date field... the catch though is that there is no option to create a date type field. So how the hell do I pass a dynamic schedule date to rules, if there are no date field types?!

CommentFileSizeAuthor
#5 rules_date_token.patch440 bytesfago

Comments

shadow_jh’s picture

Component: Rules Core » Rules Engine

I should probably say what Im trying to achieve. Basically, I want my select box field on my node which looks like this:

+1 day|daily
+1 week|weekly
+1 month|month

to become the scheduled components data selector field. However, that field does not show up as an option currently.

fago’s picture

Title: dynamic scheduling based on field » Add "calculate data value" action
Version: 7.x-2.0-alpha5 » 7.x-2.x-dev
Category: support » task
Priority: Critical » Normal

Oh, you would need a duration field then. However one can use an integer in 'seconds' as duration, so if you create a integer list you should be able to use it as duration.

Still, we are missing a way to do "Date + duration". I'd suggest we add a "Calculate data value" action which is able to some basic math with variables based on the date type, e.g. for dates only support +-, while for numbers we could support +-*/.

shadow_jh’s picture

At the very least I should be able to use custom php to calculate the correct time of scheduling. That however does not seem to work either.

thechanceg’s picture

Subscribe

fago’s picture

Title: Add "calculate data value" action » dynamic scheduling based on field
Status: Active » Needs review
StatusFileSize
new440 bytes

>At the very least I should be able to use custom php to calculate the correct time of scheduling. That however does not seem to work either.

You should be able to do that by using data selection & select just anything, then apply the PHP data processor to return whatever you want.

Anyway, at least we might want to enable tokens as that might already suffice for your use-case? For PHP evaluation the date text input field is too small I think.
Patch attached.

@calculate: I've opened #1151738: Support calculations for that.

fago’s picture

Status: Needs review » Fixed

As we have the calculation action now, using that is the preferred way I guess.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Gray Fox’s picture

Category: task » support
Status: Closed (fixed) » Active

I'm re-opening this as support request, since I'm still unable to create a scheduled rule to be executed X (integer type) days after an event date (date type). I also can't seem to use an integer list as duration (from #2).

EDIT: I ended up crafting my own module for that.

function rules_duration_rules_action_info() {
  return array(
    'rules_duration_create_duration' => array(
      'label' => t('Create a duration from a number of seconds'),
      'group' => t('Custom'),
      'parameter' => array(
        'number_of_seconds' => array(
          'type' => 'integer',
          'label' => t('Number of seconds')
        )
      ),
      'provides' => array(
        'duration' => array(
          'type' => 'duration',
          'label' => t("Duration")
        )
      )
    )
  );
}

function rules_duration_create_duration($number_of_seconds) {
  return array(
    'duration' => $number_of_seconds
  );
}

Turns out extending rules is pretty simple. Still, I think core should have some functionality like this, or I missed something obvious. Waiting for maintainer to give his opinion.

fago’s picture

Status: Active » Fixed

You can just specify now + a fitting date offset (number of days) as scheduled date.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

jraviotta’s picture

Component: Rules Engine » Rules Core

This is 90% of the solution that I need. The only problem is that I can't get a variable offset into the calculation. Perhaps I am overlooking a simple fix. Here is the use case:

I have a list of template tasks. Each task has a due date defined as an offset value (integer # of days) + "now".

On group creation, each task template node is copied to a new new content type one field at a time, and assigns the new group og_group_ref through rules. l can get everything to work fine except for the calculation of the specific due date for the copied group-specific tasks since there is no data selector for duration in the date calculation. This function requires a known value. Since the offset value for different tasks is variable, I can't use them in the calculation.

I'm working on creating a custom action that does the math, but i think this functionality could be useful to other rules users.

I have also had a hard time understanding what the php evaluation fields are capable of doing. For example, I finally found this thread that told me that custom PHP could not set variable values, but I tried that approach for too long before searching to see if It was possible. I would love a handbook page about how they should/should not be used.

If there is a way to use a token value in the duration field, or some php evaluation, perhaps someone could help me understand that strategy.

thanks in advance for your help!

danon1981’s picture

I have ran into a similar situation where I need to be able to schedule based on a dynamic value so I have put in a feature request for this feature Schedule offset based on entity value

jimafisk’s picture

Issue summary: View changes

I wrote a custom action that may be similar to what jraviotta was looking for: https://www.drupal.org/sandbox/jimafisk/2663768

Basically you can take an existing date value, then pass a strtotime() parameter such as "+1 day" or "next Thursday" and it will create a variable with the combination that you could then use to schedule a component or do whatever you want.