anteo / redmine_custom_workflows

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

How to set value of a custom field back to its default/initial value? #309

Closed T0mek closed 1 year ago

T0mek commented 1 year ago

Hi all,

I have code that clears values of some custom field when the issue is copied from another issue:

if  @issue.new_record?  &&  @issue.copy?

  #clear dates 
  self.custom_field_values = {14 => '' }
  self.custom_field_values = {13 => '' }
...

But for some another fields I do not want to clear its values, but set the default value. The question is: how to set value of a custom field back to its default/initial value?

Tomek

AirTibu commented 1 year ago

Hi,

Use this code:


if  @issue.new_record?  &&  @issue.copy?
  #clear dates 
self.custom_field_values = { '14'=> CustomField.find_by_id(14).default_value.to_s }
self.custom_field_values = { '13'=> CustomField.find_by_id(13).default_value.to_s }
...

I hope it helps!

T0mek commented 1 year ago

Hi,

Use this code:


if  @issue.new_record?  &&  @issue.copy?
  #clear dates 
self.custom_field_values = { '14'=> CustomField.find_by_id(14).default_value.to_s }
self.custom_field_values = { '13'=> CustomField.find_by_id(13).default_value.to_s }
...

I hope it helps!

It works! Many thanks! Tomek