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?
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Jeremy Gaudet thanks for sharing. nice solution.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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: []
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.