K
K
Kirill Djonua2015-12-02 13:07:49
Redmine
Kirill Djonua, 2015-12-02 13:07:49

How to pull out a custom field from a plugin in Redmine?

Good day.
There are Custom Fields in redmine, I created one and want to access it from a plugin.
The first thing that comes to mind is this:

if issue.respond_to?(:custom_field_values)
      issue.custom_field_values.each do |cfv|
        if cfv.respond_to?(:custom_field)
          c_field = cfv.custom_field

          if c_field.respond_to?(:name) and (c_field.name == "Название настраиваемого поля") and cfv.respond_to?(:value)
            id = cfv.value.to_i > 0 ? cfv.value.to_i : nil

            if id.present?
              return User.where(id: id).take
            end
          end
        end
      end
    end

since the custom field doesn't have an ID, you have to look it up by name. Maybe there is an easier way that I'm not aware of?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Pitin, 2015-12-03
@tdvsdv

I can't tell you the code, but here it is
tin of course. Why did you decide that custom fields do not have id. Everything is :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question