Is there a way to clear the fixVersion field if the Resolution value != "Fixed"?

When a bug issuetype closes with a Resolution value that is not "Fixed", we prefer to not post a "fixVersion" value or set of values.  For example, if the resolution was "Invalid", we don't want an issue to close with any version values in the fixVersion field.  Is there a way to clear the fixVersion field based on the value of Resolution? Thank you.

1 answer

Using Script Runner, you could do that in a post-function.  I have a similar requirement, but I used a custom validator (again, Script Runner) to prevent the closure, that way the developer has an opportunity to change the resolution instead of clearing the field.  Here's the code, if you are interested:

import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.project.version.Version;
import com.opensymphony.workflow.InvalidInputException;

Collection<Version> fvs = issue.getFixVersions();


Boolean hasFV = (fvs != null && !fvs.isEmpty());


String fixedResolution;
switch (issue.getIssueTypeObject().getName()) {
    case "Sub-Defect":
    case "Bug":
        fixedResolution = "Fixed";
        break;
    case "Improvement":
        fixedResolution = "Implemented";
        break;
    default:
        fixedResolution = "Completed";
        break;
}


if (hasFV && issue.getResolutionObject().getName() != fixedResolution) {
        invalidInputException = new InvalidInputException("If \"Fix Version/s\" is set the resolution must be \"" + fixedResolution + "\".");
}
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.project.version.Version;
import com.opensymphony.workflow.InvalidInputException;


Collection<Version> fvs = issue.getFixVersions();


Boolean hasFV = (fvs != null && !fvs.isEmpty());


String fixedResolution;
String errorString;
switch (issue.getIssueTypeObject().getName()) {
    case "Sub-Defect":
    case "Bug":
        fixedResolution = "Fixed";
        break;
    case "Improvement":
        fixedResolution = "Implemented";
        break;
    default:
        fixedResolution = "Completed";
        break;
}

if (issue.getIssueTypeObject().isSubTask()) {
        errorString = "\"Fix Version/s\" (synched from the parent issue) is required when specifying Resolution of \"" + fixedResolution + "\".";
} else {
        errorString = "\"Fix Version/s\" is required when specifying Resolution of \"" + fixedResolution + "\".";
}


if (!hasFV && issue.getResolutionObject().getName() == fixedResolution) {
        invalidInputException = new InvalidInputException(errorString);
}

Note that I use two validators, one to require that they set a FixVersion if they are setting the resolution to Fixed, and one to require that the resolution be Fixed if they set a FixVersion.  That may be a little more involved than your needs, but it's what I've got; the second one covers your case, in that if they didn't use a fixed terminal state, FixVersion would not be allowed to be set.

An explicit update of FixVersion in a post function should just be something like:

import com.atlassian.jira.issue.MutableIssue; 
MutableIssue issue = issue;
 
if(issue.getResolutionObject().getName() != "Fixed") {
     issue.setFixVersions(null);
}

Thank you for the quick response Jeremy!  I see Script Runner is a plugin for Server.  We are on Cloud.  Is there a way to do this on the Cloud version? 

The only way I can think of would be to do it in a post-resolved transition, where you use a condition based on the value of Resolution to fork the transition such that, if the resolution is Fixed, the transition to the next status explicitly clears the field, and if the resolution is not Fixed, the transition to the next status does not (I'm assuming both the "Field Value" condition and the "Clear Field" post function are available on cloud).  This would leave it set until, say, the issue was Closed, and you wouldn't be able to skip "Resolved" on your way to Closed.

There may be a less convoluted way here, but I don't know of it, as I'm not familiar with the cloud version.   Hopefully, if that's the case, someone else answers.


Note that you can make both transitions show up as, say, "Close Issue" by setting workflow properties on them.  The default "Close Issue" should have the properties pre-set, so you'd just have to copy them.  So you'd have "Close Issue" and "Close Fixed Issue", for example, in the workflow, but they'd both show as "Close Issue" in the UI (with the condition ensuring that you only see one at a time).

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,001 views 12 18
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot