Documentation for JIRA 4.1. Documentation for other versions of JIRA is available too.
Confusingly, the method setCustomFieldValue
on the MutableIssue
does not actually set the custom field value of an issue. To update a custom field value on an issue, you'd need to use the method updateValue
on the CustomField
object itself.
Since JIRA 3.4.x the updateValue method signature has changed to:
/** * Update the issue in the data store * * @param fieldLayoutItem for this field within this context * @param issue Issue this field is part of * @param modifiedValue new value to set field to. Cannot be null. * @param issueChangeHolder an object to record any changes made to the issue by this method. */ void updateValue(FieldLayoutItem fieldLayoutItem, Issue issue, ModifiedValue modifiedValue, IssueChangeHolder issueChangeHolder);
The fieldLayoutItem is used to determine whether the wiki renderer is used or not and can be null for non-renderable fields only. The issueChangeHolder
is used to store and then possibly write the change history. You can simply replace this with new DefaultIssueChangeHolder
and it should still work out.
For example, here is some code that updates a "Timestamp" non-wiki text custom field on issue "TP-14":
IssueManager issueManager = ComponentManager.getInstance().getIssueManager(); CustomFieldManager cfManager = ComponentManager.getInstance().getCustomFieldManager(); MutableIssue issue = issueManager.getIssueObject("TP-14"); CustomField cf = cfManager.getCustomFieldObjectByName("Timestamp"); IssueChangeHolder changeHolder = new DefaultIssueChangeHolder(); cf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf), ""+new java.util.Date()),changeHolder); System.out.println(changeHolder.getChangeItems().get(0));