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

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 Join to answer
Community showcase
Teodora [Botron]
Published Thursday in Marketplace Apps

Jira Inferno: The Nine Circles of Jira Administration Hell

If you spend enough time as a Jira admin - whether you are managing a single, mid-sized instance, a large enterprise one or juggling multiple instances at once - you will eventually find yourself in ...

646 views 4 15
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
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