Hi,

Lately I created some rules to set a start and end date on the saved node.
The start/end date fields are of type date with a popup selector.

The choosen event was fired, the rules debug text said: "100.252 ms Evaluating the action data_set. [edit]"
No error! But the date fields stayed empty!?!

In the rules I check for the date fields:

      { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_guide_from" } },
      { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_guide_to" } },

and this is how I want to set the values:

      { "data_set" : { "data" : [ "node:field-guide-from" ], "value" : "now" } },
      { "data_set" : { "data" : [ "node:field-guide-to" ], "value" : "now +1 year" } },

Since I updated the Date module from 2.3 to 2.5, I can't directly access the value anymore ([ "node:field-guide-to:value" ])

Environment:
Rules version 7.x-2.1
Date version 7.x-2.5
Entity API version 7.x-1.0-rc1

Any ideas, help!?!

Thx, ifux

Comments

ifux’s picture

Additional information:

There's a notice in the reports that says: The variable or parameter 0 is empty.
But first time it has to be empty!?

ifux’s picture

hi there,

found some time to go through my rules again and trying to debug.

I trigger my rules on my own (created) event, so I tried it once with the node-update event.
Then the date setting worked! So I thought perhaps I set the date "to late" and have to save the entity again, so I changed back to my own event and added a "save entity" action... no date set :-(

But there is a fact that is somehow suspicious:

0 ms Reacting on event MY EVENT..
...
    464.003 ms Evaluating conditions of rule MY RULE. [edit]
...
    468.734 ms The condition entity_has_field evaluated to TRUE [edit]
    469.106 ms The condition entity_has_field evaluated to TRUE [edit]
    469.61 ms The condition data_is_empty evaluated to TRUE [edit]
...
    594.37 ms Saved node of type node.
        0 ms Reacting on event NODE UPDATE.
...
    0 ms Rule DATE CHANGED => SET REMINDER fires.
        5.823 ms Evaluating the action schedule. [edit]
        8.906 ms Rule DATE CHANGED => SET REMINDER has fired.

Looks like the entity is being saved AND it fires a rule that reacts on date value change?!?!?!

Any ideas/advices!?! Would be great!!!

thx, ifux

berdir’s picture

Status: Active » Postponed (maintainer needs more info)

Cannot reproduce this with the following, simple rule. I assume this is a combination of multiple rules or custom code that change stuff that they shouldn't.

{ "rules_set_date" : {
    "LABEL" : "Set Date",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules" ],
    "ON" : [ "node_presave" ],
    "IF" : [
      { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_date" } }
    ],
    "DO" : [ { "data_set" : { "data" : [ "node:field-date" ], "value" : "now" } } ]
  }
}
wipeout_dude’s picture

Status: Postponed (maintainer needs more info) » Active

I am having the same issue..

I have an "attendance" field to store a start date/time and end date/time record..

To test I created a run "when item is viewed" - "content is of type " - "set data value - attendance date 'value' = now"..

It didn't appear to do anything, the rule was running because it was displaying a "system message" but the date field was not updating..

I thought it maybe because the field required an end date so I removed the requirement but it still didn't save the field..

Not sure how else to test it to get closer to why its not working..

ifux’s picture

YES! It finally works!

I don't really know why?!

I change the "place" where my rules gets invoked. First I invoked it in the first submit function of the button and know I invoke it in the last submit function of the button.

Can anybody explain to me why and what that changes?!? I thought 'cause the form_state variable is pasted by ref, it should take all the changes on from one submit function to the other.

By the way, the date fields should not be touched in any other submit function I have!

fnapo’s picture

Same stuff, "Set a data value" from a Rule Parameter (date start and stop) doesn't actually change the node field date (start - end)
Date API 7.x-2.5
Rules 7.x-2.1

ptmkenny’s picture

Just a heads up-- I recently traced an issue with "set a value" to entity rc3 and entity translation alpha2.

fnapo’s picture

Reverting to Entity rc1 worked for me too

fnapo’s picture

Debugging Rules Component, I actually found this error for updating a date field:

14.824 ms Unable to modify data "nodo:field-ga-data:value2": Unable to set the data property value2 as the parent data structure is not set.
15.025 ms Unable to evaluate action data_set. [edit]

what do you think is the core problem?

thanks

eliaspallanzani’s picture

with Rules version 7.x-2.2
Date version 7.x-2.6

trying to set a date field with a text
php

$field = field_get_items('entity', $entity, 'field_datina');
$field1= date('Y-m-d', strtotime($field));
$value = $field1[0]['value'];
return $value;

don't work
and dont' work with integer, with text...

tobiasb’s picture

Category: bug » support

I updating a date field (unix timestamp) with the http://drupal.org/project/interval module. Which works fine.

ptmkenny’s picture

Category: support » bug

@tobiasb This is a bug report about an incompatibility with the Rules module. Since both Date and Rules are in widespread use, this is an issue for many people. Please don't change the category without good reason.

koppie’s picture

Status: Active » Closed (duplicate)

Apparently this will only work if the field already has a default value. See #1431952: Date field will only set in Rules if it already has a value.

I'm marking this issue as a duplicate, even though the other issue is for the Date module. Feel free to reopen this issue (and close that one) if you can provide a solution that is Rules-centric.

koppie’s picture

Issue summary: View changes

Typo ;-)

dan.mantyla’s picture