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

Lorraine Gorman March 29, 2016

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

1 vote
Jeremy Gaudet
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 29, 2016

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);
}
Lorraine Gorman March 29, 2016

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? 

Jeremy Gaudet
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 29, 2016

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 Sign up to answer