You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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.