How do I save a value into a custom field in JIRA programmatically?

后端 未结 4 1237
粉色の甜心
粉色の甜心 2020-12-30 06:24

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 an

4条回答
  •  不知归路
    2020-12-30 07:00

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

    Comments welcome...

    private void saveValue(MutableIssue issue, String valueToSave, CustomField
            customField) throws FieldLayoutStorageException {
    
        issue.setCustomFieldValue(customField, valueToSave);
    
        Map 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);
    }
    

提交回复
热议问题