Project

General

Profile

Setting a custom field to the value of the ticket id (with custom workflow plugin).

Added by Thomas Steinert about 10 years ago

Hi,

when a ticket is created I want to set the value of a custom field (named Number) to the #id of the ticket which is automatically assigned to the ticket after creation. The custom workflow plugin offers a after_save hook. When this hook is called I assume that the ticket number has been assigned at this point.

My problem is that I don't know how to change the value of a custom field within this hook as I don't understand how to take hold of the specific variable and how to get the ticket number.

I tried those two ways whereby status_id 12 means new/pendings and the custom field's id that I want to change is 9. The first way throws a Fixnum error and the second way just don't do anything.

if status_id_changed?
  if status_id==2
    update_attribute(custom_field_values[4], id)
  end
end

and

if status_id_changed?
  if status_id==2
    custom_field_values[4] = id
  end
end

Here are my specs:

Environment:
  Redmine version                2.4.3.stable
  Ruby version                   2.0.0-p353 (2013-11-22) [x86_64-linux]
  Rails version                  3.2.16

Redmine plugins:
  redmine_custom_workflows       0.0.4