Hi-
I am wanting to add a script to Jira to store the changes to the FixVersion field. I've created a new field, PreviousFixVersion, to store the list of versions. This field is the same type as the FixVersion field. I can't seem to find a method to let me set the values.
I've tried the following script in ScriptRunner:
import com.atlassian.jira.component.ComponentAccessor
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
// Get the custom field objects for FixVersion and PreviousFixVersion
def fixVersionField = customFieldManager.getCustomFieldObjectsByName("Fix Version").first()
def previousFixVersionField = customFieldManager.getCustomFieldObjectsByName("PreviousFixVersion").first()
// Get the current issue and its current and previous FixVersion values
def currentFixVersions = issue.getCustomFieldValue(fixVersionField)
def previousFixVersions = issue.getCustomFieldValue(previousFixVersionField) ?: new ArrayList()
// Get the previous FixVersion value before the update
def changeLog = issue.changelog
if (changeLog) {
def changedValue = changeLog.getRelated("ChildChangeItem")?.find {it.field == "Fix Version"}
if (changedValue && changedValue.oldstring) {
def versionManager = ComponentAccessor.getVersionManager()
def previousVersion = versionManager.getVersion(issue.projectObject.id, changedValue.oldstring)
// Add the previous FixVersion value to PreviousFixVersion field if not already present
if (previousVersion && !previousFixVersions.contains(previousVersion)) {
previousFixVersions.add(previousVersion)
issue.setCustomFieldValue(previousFixVersionField, previousFixVersions)
issueManager.updateIssue(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(), issue, com.atlassian.jira.event.type.EventDispatchOption.DO_NOT_DISPATCH, false)
}
}
}
However the issue.setCustomFieldValue call doesn't work.
I am using Jira on-premise version 8.20.17. I also have Automation for Jira and ScriptRunner installed.