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 custom fields in an issue #302

Closed vomus closed 1 year ago

vomus commented 1 year ago

Hi! is there any example somewhere I can look at to see how to set a value for a certain custom field at a particular task?

picman commented 1 year ago

https://github.com/anteo/redmine_custom_workflows/wiki/Example-Workflows

vomus commented 1 year ago

I am not very much of a Ruby expert. This works in the console when I experimented:

iss = Issue.Find(2722)
iss.custom_value_for(5).value = Time.now.strftime('Note.%d%m%H%M%S-%y')
iss.save!

but this does not work inside custom_workflow:

@issue.custom_value_for(5).value = Time.now.strftime('Note.%d%m%H%M%S-%y')
dmakurin commented 1 year ago

You can set the value of a custom field in before_save callback:

self.custom_field_values = { '5' => Time.current.strftime('Note.%d%m%H%M%S-%y') }

Check FAQ, there are plenty tips how to use plugin features https://github.com/anteo/redmine_custom_workflows/wiki/Frequenly-Asked-Questions#how-can-i-access-and-manipulate-custom-fields

vomus commented 1 year ago

Yeah, I also found/figured a little other way

icf = IssueCustomField.find_by_name('Note id')
self.custom_field_values = { icf.id => Time.now.strftime('Note.%d%m%H%M%S-%y')  }

so one does not need to poke in the DB to look for a custom field id... Thanks.