anteo/redmine_custom_workflows

Check if version.due_date has changed

Closed this issue · 5 comments

How can I check if version.due_date has changed and get the previous value?

On custom fields I usually use something like:

@original_value = self.custom_value_for(id).try(&:value)

To get the original value... but, unfortunately, there is not a value method for due_date, neither a _changed? property.

Many thanks in advance.

I think that you can ask for version.effective_date value in the database in before_save script.

Thanks for your help!

I am sorry, but I have no idea about how to ask database from a workflow, and couldn't find any example

I have tried with:

(before saving)
@original_value_due = self.effective_date
(after saving)
if self.due_date != @original_value_due && !@original_value_due.nil?

As expected... it doesn't work :(

 @original_value_due = Version.where(id: self.id).pluck(:effective_date)

Thank you so much for your support!!!!

It works!

There was a bug in my code... if you want to compare self.due_date with @original_value_due, you must take into account that @original_value_due will return an array, so it is neccesary to get the first element

@original_value_due = Version.where(id: self.id).pluck(:effective_date).first