Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Update fixVersion field on transaction

Andrey Glazkov
Contributor
December 13, 2019

I have project with kanban board. When I release issue fixVersion field is updated.

But when i reopen released issue fixVersion field doesn't change so i don't see this issue on the board.

What is best way to update fixVersion field when transition happens? If it is no built-in way I have ScriptRunner on my Jira instance so could use it.

1 answer

1 accepted

0 votes
Answer accepted
Leo
Community Champion
December 13, 2019

Hi @Andrey Glazkov,

You can use below script for updating fix version field in post-function

import com.atlassian.jira.component.ComponentAccessor

def versionManager = ComponentAccessor.getVersionManager()
def project = issue.getProjectObject()
def version = versionManager.getVersion(project.getId(), "version name")

if (version) {
issue.setFixVersions([version])
log.warn("${issue.key} - fix version/s has been updated with ${version}")
}
else{
log.warn("Version does not available")
}

 

BR,

Leo

Andrey Glazkov
Contributor
December 15, 2019

Hello, Leo and thanks for response!

Apparently I expressed myself inaccurately. I needed to clean up fixVersion field when issue moved from Closed status to any other statuses.

Your solution is correct but too complex for my case. After some investigation I googled apropriate solution:

In Post-Function menu select "Script Post-Function [ScriptRunner]" then select "Custom script post-function".

Use this script for post-function:

import com.atlassian.jira.issue.MutableIssue; 
MutableIssue issue = issue;
issue.setFixVersions(null);

 

Leo
Community Champion
December 16, 2019

hey, I thought you wanted to change fix version. but if you want to remove fix version/s value is quite easy and simple. just single line code is enough

issue.setFixVersions([])
log.warn("${issue.key} - fix version/s has been updated")

 

BR,

Leo

Like Andrey Glazkov likes this
Jonas Frid June 24, 2020

Hi @Leo !

I tried 

issue.setFixVersions([])

in our environment (Jira 8.8.1, SR6.0.1-p5) and get the following error: 

image.png

Has there been a change in the API affecting how to clear FixVersions for an issue?

BR/Jonas

Leo
Community Champion
June 24, 2020

@Jonas Frid

my environment is 8.5.3 with 6.1.0 but no error

maybe you can give a try with below code

issue.setFixVersions(null)

 

BR,

Leo

Jonas Frid June 26, 2020

@Leo 

Finally found that 6.0.1 suffered from:

SRJIRA-4308 - The type of issue in post-function was incorrectly Issue and not MutableIssue.

This was solved in 6.1.0.

(The code you suggested was my original code version where I discovered the error mesage ... so it was of course a good and valid suggestion ;-) )

 

BR/Jonas

Suggest an answer

Log in or Sign up to answer