如何使用 java 更新 jira 7+ 中的自定义字段
How to update custom field in jira 7+ using java
这个问题的答案在我检查过的所有来源上都已过时或不完整。
这里有一些例子:
How do I save a value into a custom field in JIRA programmatically?
Automating custom field value change in JIRA
Jira: How to obtain the previous value for a custom field in a custom IssueEventListener
CustomFieldManager is not getting the custom field after modifying the custom field name using REST api in jira
我没有足够的声誉来评论这些问题中的任何一个。但是我有一个答案。
所以这是我的决定:
CustomField csUserField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName(fieldName);
IssueService issueService = ComponentAccessor.getIssueService();
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
issueInputParameters.addCustomFieldValue(csUserField.getId(), value_string);
issueInputParameters.setSkipScreenCheck(true);
issueInputParameters.setRetainExistingValuesWhenParameterNotProvided(true, true);
UpdateValidationResult updateValidationResult = issueService.validateUpdate(user, issue.getId(), issueInputParameters);
if (updateValidationResult.isValid())
{
IssueResult updateResult = issueService.update(user, updateValidationResult);
if (!updateResult.isValid())
{
log.warn("ISSUE has NOT been updated. Errors: {}\n", updateResult.getErrorCollection().toString());
}
else
{
log.warn("ISSUE has been updated.\n");
}
}
else
{
log.warn("ISSUE has NOT been updated. Errors: {}\n", updateResult.getErrorCollection().toString());
}
这个问题的答案在我检查过的所有来源上都已过时或不完整。
这里有一些例子:
How do I save a value into a custom field in JIRA programmatically?
Automating custom field value change in JIRA
Jira: How to obtain the previous value for a custom field in a custom IssueEventListener
CustomFieldManager is not getting the custom field after modifying the custom field name using REST api in jira
我没有足够的声誉来评论这些问题中的任何一个。但是我有一个答案。
所以这是我的决定:
CustomField csUserField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName(fieldName);
IssueService issueService = ComponentAccessor.getIssueService();
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
issueInputParameters.addCustomFieldValue(csUserField.getId(), value_string);
issueInputParameters.setSkipScreenCheck(true);
issueInputParameters.setRetainExistingValuesWhenParameterNotProvided(true, true);
UpdateValidationResult updateValidationResult = issueService.validateUpdate(user, issue.getId(), issueInputParameters);
if (updateValidationResult.isValid())
{
IssueResult updateResult = issueService.update(user, updateValidationResult);
if (!updateResult.isValid())
{
log.warn("ISSUE has NOT been updated. Errors: {}\n", updateResult.getErrorCollection().toString());
}
else
{
log.warn("ISSUE has been updated.\n");
}
}
else
{
log.warn("ISSUE has NOT been updated. Errors: {}\n", updateResult.getErrorCollection().toString());
}