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

后端 未结 4 1216
粉色の甜心
粉色の甜心 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

    Here a solution that works for me in JIRA 6.4.7 to update a custom field value. Actually Im updating a single select field, therefore I have to get the Option for it:

    MutableIssue issue = issueManager.getIssueByCurrentKey(issueKey); 
    FieldConfig relevantConfig = customField.getRelevantConfig(issue);
    // if you use a text field use String. or double for numeric
    Option optionForValue = optionsManager.getOptions(relevantConfig).getOptionForValue(option, null);
    issue.setCustomFieldValue(customField,optionForValue);
    Map modifiedFields = issue.getModifiedFields();
    FieldLayoutItem fieldLayoutItem =
    fieldLayoutManager.getFieldLayout(issue).getFieldLayoutItem(customField);
    DefaultIssueChangeHolder issueChangeHolder = new DefaultIssueChangeHolder();
    final ModifiedValue modifiedValue = modifiedFields.get(customField.getId());
    customField.updateValue(fieldLayoutItem, issue, modifiedValue, issueChangeHolder);
    

提交回复
热议问题