Jira - 单选自定义字段 通过接口添加选项
Max.Bai
2019-10
目录
1. 背景
Jira里面自定义字段的选择需要在admin页面配置
Administration panel > Custom fields > configure > Edit options
有没有可以自动添加的接口什么的,经过查找,找到如下资源,先行mark,待有空来验证。
2020-03-13 更新,发现插件可以实现,看第3节
2. 信息
摘抄一下,以免信息丢失。
Followed this tutorial: https://developer.atlassian.com/server/framework/atlassian-sdk/developing-a-rest-service-plugin/
Added following method to the Rest Resource class (MyRestResrouce.java in the tutorial).
/**
* This method is to be used whenever a new option is to be added to a custom field. It will add it to the top of the list.
* @param fieldId - custom field id, e.g,. customfield_10000
* @param optionVal - option value, e.g,. 4.1r1.24.67643_70
* @return
*/
@GET
@AnonymousAllowed
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Path("/addOptionsToCustomField")
public Response addOptionToCustomField(@QueryParam("fieldId") String fieldId, @QueryParam("optionVal") String optionVal)
{
CustomFieldManager customFldMgr = ComponentAccessor.getCustomFieldManager();
OptionsManager optionsManager = ComponentAccessor.getComponentOfType(OptionsManager.class);
if (fieldId == null || fieldId.trim().equals("")) {
return Response.ok(new ZRestResourceModel("default","Missing custom field id")).build();
}
//error checking code snipped
CustomField customField = customFldMgr.getCustomFieldObject(fieldId);
//error checking code snipped
List<FieldConfigScheme> schemes = customField.getConfigurationSchemes();
if (schemes != null && !schemes.isEmpty()) {
FieldConfigScheme sc = schemes.get(0);
MultiMap configs = sc.getConfigsByConfig();
if (configs != null && !configs.isEmpty()) {
FieldConfig config = (FieldConfig) configs.keySet().iterator().next();
Options ops = optionsManager.getOptions(config);
if(ops != null &am