Make FixVersion Required only on specific Resolution Types

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

Accepted Answer
1 vote

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.

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.

@Jeremy Gaudet thanks for sharing.  nice solution.

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
Community showcase
Published 2 hours ago in Sourcetree

Tip from the team: configure your repos for hosting goodness!

Supported Platforms macOS Windows We recently introduced support for additional hosting services such as GitHub Enterprise, GitLab (Cloud, Community Edition, Enterprise Edition), and...

35 views 0 1
Read article

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