Make FixVersion Required only on specific Resolution Types

Peter Kahn
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.
April 25, 2016

Hi all,

 

How do I require FixVersion on resolution transition only if specific resolution type chosen?  At present, I use Required Field validator which forces fix version chosen for all resolution types but I really only care for fixed/won't fix and not for duplicate.

 

Is there a way to use a validator in an if?  

1 answer

1 accepted

1 vote
Answer accepted
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.
April 25, 2016

I've done this using a Script Runner scripted validator.  I broke it up into two separate validators for ease of modular deployment, they are:

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);
}

The "RequireFixedIfFixVersion" validator covers your "Duplicate" case, in that it won't let them set a FixVersion for anything except the valid "fixed" terminal states.  You can adjust as needed, of course, these are just examples of how I did it.

I implemented these as script files in /home/jira/jira_data/scripts, for ease of re-use, but if you only have one or two transitions you need them on, and only one workflow, then inline is likely the way to go.

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.
April 25, 2016

Oh, and don't mine my "(synced from the parent issue)" part; I have a script listener that syncs fix version to all sub-tasks, so that they don't have to be set manually, and can't drift away from the parent.

Peter Kahn
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.
April 25, 2016

@Jeremy Gaudet thanks for sharing.  nice solution.

Peter Kahn
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.
October 14, 2016

Funny, I just tried this and am getting the following error which seems really weird as I'm not importing that class nor can I seem to find that other class or its javadoc

 

An unknown exception occured executing Validator 
com.atlassian.jira.workflow.SkippableValidator@635ba7c5: 
root cause: No signature of method: 
com.innovalog.jmwe.IssueProxy.getFixVersions() is 
applicable for argument types: () values: []

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events