Hello,
I have a question I would like to make a condition that wouldn't allow an issue to be closed if it has less than two labels.
Any ideas how could I achieve that? I tried using script runner but I'm not familiar enough with groovy to do that.
BR, Olga
Hi @Olga Videc,
Add Script Condition -> Custom Script Condition, than paste the following code;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.label.LabelManager;
passesCondition = false;
LabelManager labelManager = ComponentAccessor.getComponent(LabelManager);
def labels = labelManager.getLabels(issue.id).collect{it.getLabel()}
if(labels.size() > 1){
passesCondition = true;
}
So, users must add at least two labels in order to see the transition button.
Tansu
Please see samples here - https://scriptrunner.adaptavist.com/5.0.2/jira/recipes/workflow/conditions/all-subtasks-resolved.html
passesCondition = true
def labels = issue.getLabels()
if(labels && labels.size() < 2) {
passesCondition = false
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Put the above condition in the "condition" section of workflow script runner and that should do the trick. Now the workflow button for close will not be visible if issue has less than 2 labels. But I have a feeling that you should put in the "validation" phase instead of condition phase that's much better.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Managed to work around added my comment in the error that appears when I run simple validator script, anyway thanks for help :D both of your scripts work :D
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello, both solutions are correct only one correction for the first one I added !=null so because I didn't work for blank, both work for condition but not for custom validator it works for simple validator but with simple validator I cant change the error message, custom validator executes but doesn't block the transition any idea why?
passesCondition = true
def labels = issue.getLabels()
if(labels != null && labels.size() < 2) {
passesCondition = false
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.