field does not get recomputed when node gets updated

Created on 11 December 2023, 7 months ago
Updated 22 December 2023, 7 months ago

How can computed field that is in use in Views get recalculated when a node gets updated?

I am trying to use a computed field for a date field and then use it in views. Let's say I have a "start date" field that a user fills in; I want the computed field (name: expiry date ; field_expiry_date) to calculate the following: $entity_field[0]['value'] = date('Y-m-d H:i', field_start_date['und'][0]['value'] + strtotime('+7 days')); which it does exactly what I want (data type: varchar; both "store in database" and "recalculate the field value every time" is checked); but when I update the field "field_start_date", the value of expiry date (field_expiry_date) does not get recalculated and updated.

I have tried to update it using "rules" but rules is stating: "The selected data property doesn't support writing" at "Add a new action page" (set a data value > node:field_expiry_date)

I am not sure if I am on a right track, any help is greatly appreciated

πŸ’¬ Support request
Status

Active

Version

1.1

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada akharabi

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @akharabi
  • πŸ‡¬πŸ‡§United Kingdom joachim

    You need to set the caching on the computed data -- see getCacheability().

    This maybe needs to be changed - are you outputting any other part of the node in the view? By default getCacheability() returns NULL, which I assumed would mean the caching is the same as the entity the field is on. But if you were outputting just that field in a view, the cacheability would be that of the view.

  • πŸ‡¨πŸ‡¦Canada akharabi

    Hi @joachim , Yes I am reading other fields in Views as well. Is there any way of forcing the "computed field" to recalculate when that node gets updated without writing a custom code? This feature should be part of it right?
    Thanks,

  • πŸ‡¬πŸ‡§United Kingdom joachim

    Oh wait is this on D7?

Production build 0.69.0 2024