anteo / redmine_custom_workflows

Allows to create custom workflows for Redmine
http://www.redmine.org/plugins/custom-workflows
GNU General Public License v2.0
178 stars 72 forks source link

Check if version.due_date has changed #345

Closed marmat1 closed 2 weeks ago

marmat1 commented 2 weeks ago

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.

picman commented 2 weeks ago

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

marmat1 commented 2 weeks ago

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 :(

picman commented 2 weeks ago
 @original_value_due = Version.where(id: self.id).pluck(:effective_date)
marmat1 commented 2 weeks ago

Thank you so much for your support!!!!

It works!

marmat1 commented 1 week ago

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