Thanks to #1153766: provide a property setter callback the Date field can now be set in Rules. However, it seems to only work if the date field already has a value. If the value is blank, it won't get set.

I'm using Drupal 7.12, Rules 7.x-2.x branch, and Date 7.x-2.x branch.

This is the error log that Rules is spitting out:
# 1.02 ms Evaluating the action data_set. [edit]
# 3.931 ms Unable to modify data "eval:field-open-date:value": Unable to set the data property value as the parent data structure is not set.
# 7.665 ms Unable to evaluate action data_set. [edit]
# 8.716 ms Evaluating the action data_set. [edit]
# 10.118 ms Unable to modify data "eval:field-open-date:value2": Unable to set the data property value2 as the parent data structure is not set.
# 11.489 ms Unable to evaluate action data_set. [edit]

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

arlinsandbulte’s picture

Project: Date » Rules
Component: Date Field » Rules Engine

Let's let fago have a look at this first.
Then it can be moved back to the date module issue queue if needed.

milos.kroulik’s picture

I also seem to have this issue, when trying to load vocabulary and set term into it. See my exported rule: http://drupalbin.com/21099

fago’s picture

Status: Active » Postponed (maintainer needs more info)

I think that should be fixed with the recent 2.1 release - please try this one.

andrea.vivaldi’s picture

Tried with 2.1 release and this error still remains (i've tried with a Data field)

c.breschkow’s picture

With the release 7.x-2.2 everything works perfect. If I upgrade to 7.x-2.3 I must enter the date field with a value. But the rule can't find this value.

webfeathers’s picture

I am getting the same behavior.
Drupal 7.12
Entity 7.x-1.0-rc1 (with entity_i18n_string patch from http://drupal.org/node/1513406#comment-5824286)
Rules 7.x-2.1
Date 7.x-2.3

Rules debugger output (subset)
----------------------
0 ms Rule Set Last Published Date fires.
2.425 ms Evaluating the action data_set. [edit]
3.336 ms Unable to modify data "node:field-last-published-date:value": Unable to set the data property value as the parent data structure is not set.
7.329 ms Unable to evaluate action data_set. [edit]
7.377 ms Rule Set Last Published Date has fired.
-------------------------------

Rule content (Pretty simple) is:

{ "rules_set_first_published_date" : {
"LABEL" : "Set First Published Date",
"PLUGIN" : "reaction rule",
"REQUIRES" : [ "workbench_moderation", "rules" ],
"ON" : [ "workbench_moderation_after_moderation_transition" ],
"IF" : [
{ "AND" : [
{ "contents_current_state" : { "node" : [ "node" ], "moderation_state" : "published" } },
{ "entity_has_field" : { "entity" : [ "node" ], "field" : "field_first_published_date" } },
{ "data_is_empty" : { "data" : [ "node:field-first-published-date:value" ] } }
]
}
],
"DO" : [
{ "data_set" : {
"data" : [ "node:field-first-published-date:value" ],
"value" : [ "site:current-date" ]
}
}
]
}
}

andypost’s picture

This works for date 2.2 but broken for date 2.3, probably caused by #1153766: provide a property setter callback

mitchell’s picture

Project: Rules » Date
Component: Rules Engine » Date Field
Status: Postponed (maintainer needs more info) » Active

Seems like something changed between Date 2.2 and 2.3. Does this bug still exist in later releases?

KarenS’s picture

Status: Active » Closed (cannot reproduce)

We're up to Date 2.5 and there have been lots of changes. If there is still a problem in 2.5 someone will have to reopen with steps to reproduce.

davidwhthomas’s picture

Title: Date field will only set in Rules if it already has a value » Date field will only set in Rules if it already has a value [FIXED]

Just a note on this one, I was getting the same error with Date 7.x-2.3. ( Unable to set the data property value as the parent data structure is not set. )

However, after upgrading to the latest 7.x-2.5, the problem was solved!

Thanks KarenS!

DT

jamescl’s picture

Title: Date field will only set in Rules if it already has a value [FIXED] » Date field will only set in Rules if it already has a value
Status: Closed (cannot reproduce) » Active

I can reproduce on clean install using dev releases.

With single date (i.e. no end date) this works fine, however when 'collect and end date' is selected in manage fields this will not work if you are setting a start or end date when both do not have a value. When you have a start date already in the field you can overwrite it, or set an end date with no trouble.

Rules debug shows:
- (For start dates) Unable to modify data "node:field-name:value": Unable to set the data property value as the parent data structure is not set.
- (For end dates) Unable to modify data "node:field-name:value2": Unable to set the data property value as the parent data structure is not set.

Requiring (or not) an end date seems to have no impact.

wipeout_dude’s picture

Same here.. If Date is empty rules won't set it.. All mine have start and end so haven't tested a single "value" date..

If date is already populated then both "value" and "value2" can be changed by a rule..

Date - 7.x-2.5
Rules - 7.x-2.1

wipeout_dude’s picture

Hi All,

Desperately need the ability to set and update date fields (start and end dates) from rules.. I haven't been able to find a suitable way to do what I need to any other way..

I don't mind contributing to someone's time to get it resolved and committed to whichever module is responsible..

jamescl’s picture

Have discovered it will set both values if you set it for the whole field (i.e. don't drill to value, value 2 level.)

Therefore you can set both values with one action without a value being set (in my case from another date field), and then set a single value with a second action to whatever.

Not sure if this will work if you don't have another date field in the content type, so leaving open - but at least there's a workaround for the moment.

wipeout_dude’s picture

@jamescl - Thanks for you reply..

Just had a crack at it and it appears that you can't set it to a relative value like "now" and the option some something like site:current-date isn't available.. oing to have to give it some thought in the morning as to where I can get a usable date from to populate the field before updating "value" and "value2" to the required values..

Really hope it works because this is a big roadblock for me at the moment..

jamescl’s picture

The only way I can think to do it would be to create a new field that is only visible to admins with a default value and use that for rule. Isn't ideal to have a completely useless set of dates for every node, but it would get the job done until a fix for this can happen.

wipeout_dude’s picture

@jamescl - I have tried this but it doesn't seem to work for me..

Only other option I would have is to create two separate fields for start date and end date but that would break all calendar functionality that I was planning with the date information which is not something I would really like to sacrifice..

Chi’s picture

maxplus’s picture

Hi,

I have the same problem using:
Date - 7.x-2.6
Rules - 7.x-2.2

I have not found a workaround for this, even when trying to use a single date without a end date.
I hope there will come a solution in het next release of the Date or Rules module...

wipeout_dude’s picture

Only work around that works is as per #16 which is copying a date field from somewhere else in your rule and then change it to what you want it to be.. A little messy but at least you can create your solution.. As you say, hopefully this gets resolved because it will help simplify my rules..

dwightlathan77’s picture

Using Date - 7.x-2.6 and Rules - 7.x-2.2 I can't use the date getter or setter on datetime fields with start and end dates, regardless of whether the end date is needed or not on objects being created. I can't reference other date objects either.

A workaround is to use php code to programmatically create the node and set initial date values. This can be done through a custom module or through the Rules UI as an action triggering the php.

I really hope someone is still working on getting this functionality working. This is a reason why a configurator may need to use php, but shouldn't be considered an excuse.

koppie’s picture

Priority: Normal » Major

Marking #1611666: Action "Set a data value" is not working for date field as a duplicate of this issue - but that one might be worth keeping an eye on, because it's in the Rules module. I'm also upgrading the priority of this issue to "major" because (a) it actually keeps things from working and (b) it's been unsolved for a year and a half.

Does anyone have any ideas for solving this? I don't even know where to start.

Cadila’s picture

Issue summary: View changes
FileSize
1.34 KB

I faced this problem today. It's really annoying. The problem is in date module that doesn't provide auto creation callback for struct dates (with begin date and end date fields). This should solve the problem.

ivanhelguera’s picture

wow, #23 worked for me. I'm all in tears! Thank you!

vijaycs85’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 23: issue1431952.patch, failed testing.

Cadila’s picture

FileSize
1.34 KB

re-uploading patch cause the old one have failed the tests

Cadila’s picture

FileSize
1.25 KB

Sorry, wrong paths again. Fixed.

andypost’s picture

Status: Needs work » Needs review
andypost’s picture

Status: Needs review » Reviewed & tested by the community

Awesome! Let's get this in

maximpodorov’s picture

Status: Reviewed & tested by the community » Needs work

Function arguments are not described in the docblock.

Cadila’s picture

FileSize
1.2 KB

Fixed phpdoc according to notice in comment #31

Cadila’s picture

Status: Needs work » Needs review
Cadila’s picture

maximpodorov’s picture

Tulika’s picture

not able to solve this issue

podarok’s picture

podarok’s picture

32: date-1431952-32.patch queued for re-testing.

maximpodorov’s picture

Status: Needs review » Reviewed & tested by the community

The patch is used on the production sites and solves the problem.

vijaycs85’s picture

Status: Reviewed & tested by the community » Fixed

Thanks @Cadila. committed 7faeea3 and pushed to 7.x-2.x

Status: Fixed » Closed (fixed)

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

gcb’s picture

FileSize
1.2 KB

Re-rolled against 7.x-2.6. Thanks for this, fixed a big issue with SF module date syncing!

lzimmerman’s picture

FileSize
1.24 KB

Re-rolled against 7.x-2.7. Worked to fix rules handling of date fields. Thanks!

maximpodorov’s picture

Maybe it's better to make a new release of Date module instead of re-rolling patches.

AaronBauman’s picture

Why are people still posting patches?
Was this fixed or not?

kopeboy’s picture

Version: 7.x-2.x-dev » 7.x-2.8
Status: Closed (fixed) » Active

I am using Date 7.x-2.8 and Rules 7.x-2.7, and still this doesn't work, neither if I have a default value for the date field (normal date field, no repeat, no interval) nor if I have a default value.

My rule fires After saving content, set the data value (all fields are loaded), and save the entity.
When I try to create that entity as a User (the date field in question is not visible to the user in the form, hided by Display Suite, no custom field permissions) I get this error "The value input for field 'My date field' is invalid." and I can't create the node.

I am using "Cache dates", maybe that is the problem?

EDIT: Ok, nevermind, even if I had no errors in the rule, I had to load the specific date field with 'Entity has field', while other fields I am saving in the same rule were working correctly just with 'Entity is of bundle' condition.

kopeboy’s picture

Status: Active » Closed (fixed)