【问题标题】:How to fetch the possible values of a custom field?如何获取自定义字段的可能值?
【发布时间】:2018-07-09 16:00:59
【问题描述】:

我创建了一个键/值对类型的自定义字段并向其中添加了一些值。我现在需要编写一个插件来创建新问题,检查主题并在该字段的可能值中找到匹配项 - 如果找到匹配项,则将该值分配给问题。
我仍在努力在我的插件中简单地获取 该字段的所有可能值。我找到了CustomField.find(id).possible_values 并尝试使用我的字段的正确ID 记录它,但它只显示[]

到目前为止我的代码:

module My_Plugin
  class Hooks < Redmine::Hook::ViewListener
    def controller_issues_new_before_save(context={ })
      issue = context[:issue]
      project = Project.find(issue[:project_id].to_i)
      if project.name === "MyProjectName"
        File.write('/tmp/redmine', CustomField.find(4).possible_values)            
      end
    end
  end
end

我做错了什么?如果我打电话给/custom_fields/4/enumerations,我可以看到很多活动字段值。

【问题讨论】:

  • 你在哪里叫它。可以出示一下代码吗?
  • @uday 我添加了代码,它在一个插件中。

标签: ruby redmine redmine-plugins


【解决方案1】:

好的,我找到了 (CustomField.find(ID_OF_FIELD).enumerations.each_with_index)。

module My_Plugin
  class Hooks < Redmine::Hook::ViewListener
    def controller_issues_new_before_save(context={ })

      issue = context[:issue]
      project = Project.find(issue[:project_id].to_i)
      if project.name === "MyProjectName"
          CustomField.find(4).enumerations.each_with_index do |value, position|
              File.write('/tmp/redmine_'+value.id.to_s, value.name)
          end
      end
    end
  end
end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-24
    相关资源
    最近更新 更多