Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

listener to copy target version/s field to fix version/s field

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

3 answers

1 accepted

0 votes
Answer accepted

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)

0 votes
Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jul 29, 2021

Hi @Jeffrey Cocozziello,

What is the type of target version/s custom field? 

 

Regards,

Leo

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

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...

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events