如何以编程方式将值保存到JIRA中的自定义字段中? [英] How do I save a value into a custom field in JIRA programmatically?

查看:980
本文介绍了如何以编程方式将值保存到JIRA中的自定义字段中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了几天时间试图找出如何以编程方式将值保存或更新到CustomField中,并最终了解它是如何完成的。所以我会把它作为一个问题,然后回答它,因为我很想有这个问题和答案。

I've spent days trying to find out how to save or update a value into a CustomField programmatically and finally found out how it's done. So I'll make this a question and then answer it as I would have loved to have this question and answer.

关于如何保存或更新JIRA中自定义字段的值。我正在使用:

There is conflicting documentation on how to save or update a value for a Custom Field in JIRA. I was using:

customField.setCustomFieldValue(CustomField, value);

这不会将值保存到数据库中,但它确实更新了值,据我所知。例如,如果您在工作流后期函数转换中进一步使用CustomField,它将非常有用。

This does not save the value into the database but it does update the value as far as I can tell. It's only useful if you are using the CustomField further down in a Workflow Post Function transition for example.

我正在使用Jira 4.3.2。

I'm using Jira 4.3.2.

如何将CustomFields值保存到JIRA数据库?

How do I persist the the CustomFields value into the JIRA database?

推荐答案

好的,这个是我如何成功更新并将CustomField值保存到JIRA数据库中。

Ok, this is how I'm successfully updating and saving the CustomField value into the JIRA db.

欢迎评论...

private void saveValue(MutableIssue issue, String valueToSave, CustomField
        customField) throws FieldLayoutStorageException {

    issue.setCustomFieldValue(customField, valueToSave);

    Map<String, ModifiedValue> modifiedFields = issue.getModifiedFields();

    FieldLayoutItem fieldLayoutItem =
    ComponentManager.getInstance().getFieldLayoutManager().getFieldLayout(issue).getFieldLayoutItem(
            customField);

    DefaultIssueChangeHolder issueChangeHolder = new DefaultIssueChangeHolder();

    final ModifiedValue modifiedValue = (ModifiedValue) modifiedFields.get(customField.getId());

    customField.updateValue(fieldLayoutItem, issue, modifiedValue, issueChangeHolder);
}

这篇关于如何以编程方式将值保存到JIRA中的自定义字段中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆