Custom_Workflows: Change Custom Field value when a specific Status is set?
Added by David Radford over 9 years ago
I've created a custom field of type Boolean called "Approved" (Custom field ID 5). I want this Boolean to automatically get checked when the status is set to "Closed" (Status ID 13).
Since Custom_Workflows get processed in the context of the issue, does this even have access to the custom_values table in the database? Try as I might, I can't seem to get it to trigger or spit out anything useful.
I would LIKE to do something like:
if @issue.status_id_changed?
if @issue.status_id==13
@custom_field_id(5).value = 1
end
end
I know that's probably way wrong in many ways, but I know basically zero about ruby scripting and even less about how it interacts/interfaces with mysql.
For testing purposes, if I run:
(forgive the broken indentation, it's indented correctly in the plugin)
if @issue.status_id_changed?
if @issue.status_id==13
raise WorkflowError, "#{@issue.id}"
end
end
It throws the error as dictated and displays the issue id. Good, I can get SOME sort of debug.
If I run:
if @issue.status_id_changed?
if @issue.status_id==13
raise WorkflowError, "#{@custom_values.id}"
end
end
I get nothing but a generic error message. So this seems to indicate that I can't access custom values? Please tell me I'm wrong.
-David
Replies (2)
RE: Custom_Workflows: Change Custom Field value when a specific Status is set? - Added by David Radford over 9 years ago
Ok, I found more documentation on the plugin: https://github.com/go2null/redmine_custom_workflows/blob/master/FAQ.rdoc
However, still can't get it to work.
Even just trying to get:
custom_field_values={"1" => "test"}
doesn't work. (Custom field ID 1 is just a text field)
I can get the inverse of what I want to work:
if custom_field_value(5) != custom_value_for(5).try(&:value)
@issue.status_id=13
end
will successfully set the status to Closed if the Approved checkbox is ticked. But I need it to work the other way around. Any ideas on what I'm doing wrong?
RE: Custom_Workflows: Change Custom Field value when a specific Status is set? - Added by @ go2null about 9 years ago
Sorry about this late reply.
if status.name == 'Closed'
icf = IssueCustomField.find_by_name('Approved')
self.custom_field_values = { icf.id => '1' }
end
BTW, Anteo has resumed development of the plugin on GitHub.
https://github.com/anteo/redmine_custom_workflows/