Hello all,
I am trying to create a listener script that copies the target version/s field to the fix version/s field whenever the issue is updated. I would be even better if I could do this whenever the field itself is updated, but I'm not sure what event to use for this.
The script I am currently using is:
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
def issue = event.issue as Issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def tgtField = customFieldManager.getCustomFieldObjects(event.issue).find {it.name == "fixVersions"}
def calcField = customFieldManager.getCustomFieldObjectsByName("targetVersions")
def changeHolder = new DefaultIssueChangeHolder()
tgtField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(tgtField), issue.getCustomFieldValue(calcField)),changeHolder)
I am using jira server version 8.13.3. I have tried using both 'Fix Version\\s' and 'fixVersions' names for both target and fix versions. I am also getting an error using the getCustomFieldValue command (but only for calcField for some reason). Any help would be appreciated!
Thanks,
Jeff
Figured it out. In case anyone is curious... I was doing two things wrong.
1) I should have used setFixVersions() rather than setFixVersion().
2) I had to update the issue after the changes are made.
Here is the final script:
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.project.version.Version
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.event.type.EventDispatchOption
def issue = event.issue as Issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def targetVersionsField = customFieldManager.getCustomFieldObject(11206)
def changeHolder = new DefaultIssueChangeHolder()
def targetVersionsList = issue.getCustomFieldValue(targetVersionsField)
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
log.warn(targetVersionsField)
log.warn(targetVersionsList)
log.warn(targetVersionsList.getClass())
issue.setFixVersions(targetVersionsList)
log.warn(issue.getFixVersions())
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Leo,
If you look at the accepted answer I recently added you will see that I found a solution, but to answer your question the custom field type was "Version Picker (multiple versions)".
Jeff
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Making a bit more progress. I learned that Fix Version/s is not a custom field and that the issue object has a way of configuring them. My latest iteration is:
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
def issue = event.issue as Issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def targetVersionsField = customFieldManager.getCustomFieldObject(11206)
def changeHolder = new DefaultIssueChangeHolder()
log.warn(targetVersionsField)
log.warn(issue.getCustomFieldValue(targetVersionsField))
def targetVersionsList = issue.getCustomFieldValue(targetVersionsField)
issue.setFixVersion(targetVersionsList)
Log:
2021-07-28 11:26:37,530 WARN [runner.ScriptBindingsManager]: Target Version/s 2021-07-28 11:26:37,535 WARN [runner.ScriptBindingsManager]: [XIQ Q2r2.2 (21.02.22.xx), XIQ Q2r3 (21.02.30.xx)] 2021-07-28 11:26:37,539 ERROR [runner.AbstractScriptListener]: ************************************************************************************* 2021-07-28 11:26:37,539 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: null groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.IssueImpl.setFixVersion() is applicable for argument types: (ArrayList) values: [[XIQ Q2r2.2 (21.02.22.xx), XIQ Q2r3 (21.02.30.xx)]] Possible solutions: setFixVersions(java.util.Collection), getFixVersions() at Script174.run(Script174.groovy:13)
I think I need to typecast the array returned by the custom field to get this to work...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.