Problem setting data value for a user field with entity reference

Events happening in the community are now at Drupal community events on www.drupal.org.
pontusgustafsson's picture

Hi!

I have a content type called "membership" with field "number_of_days" (int).
I have a entity reference field on users account called "membership_reference" along with a "start_date" (date) and a "stop_date" (date) field.

Now I want to use the value of "number_of_days" to set a new value for "stop date", something like: now +[number_of_days] days

This is my setup:
Event:
After updating an existing user account

Condition:
User has roles: Parameter: Användare: [account], Roller: membership
Entity has field: Parameter: Entitet: [account:field-membership-reference], Fält: field_number_of_days

Action:
Show a message on the site: Parameter: Entitet: [account:field-membership-reference], Fält: field_number_of_days
Set a data value: -

And my problem is that I can't choose "number_of_days" when setting a data value. BUT, if I choose Show a message on the site I can find the value for this and print it with no problems.

Do you have any ideas how to solve this? I'm I missing something? I've also tried fetch entity by property but no results so far.

Versions:
Drupal 7.15
Rules 7.x-2.2
Entity reference: 7.x-1.0-rc3

Very grateful if anyone can help!

/Pontus

Comments

What type of field?

itangalo's picture

Rules has a neat offset functionality for setting dates, which might be useful for this case. In the best of worlds you could set the end date by just entering the start date and add the number_of_days as offset.

However, there might be two problems:

1) I'm not sure that Rules likes combining a date field with an integer field. (Assuming that number_of_days is an integer.)
2) I'm pretty sure that the offset doesn't accept replacement patters or data selectors – only fixed values.

If I'm right, then I think these two approaches could do the trick:

a) Find a way to calculate a new value, adding the start date and the number_of_days. There are some calculation actions available, but again, adding a date and an integer may be problematic.
b) Write a custom action for your site, and use it to calculate the end date. Writing actions might sound difficult, but it is actually quite easy and quite fun. These links have tutorials on how to do it: http://skillcompass.org/resource/rules-mastery-training-document, http://skillcompass.org/resource/tiny-book-rules

Good luck!

Rules

Group organizers

Group categories

Categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: