I'm trying to script a validator for the create-transition which only allows one label to be chosen, and this label needs to be one of three specific labels depending on the issue type.
Several issuetypes are using the same workflow, and this validator should only affect two of the issue types (Google Analytics and Marketing), the two issuetypes each have 3 labels the user should be able to choose one of.
The reason I'm not using custom fields for this, is to prevent the creation of too many unnecessary custom fields, and that it's not possible to assign different context to different issuetypes within the same project so that each issuetype can have different options while using the same custom field.
Google Analytics allowed labels: Tracking, Analysis and Issue
Marketing allowed labels: Tracking, New_Feature and Issue
All other issuetypes won't be using labels.
I'm using the JMWE scripted validator with a groovyscript.
The script I've got so far is:
if (issue.getAsString("issuetype") == ("Google Analytics") && (!issue.get("labels")?.any{it.label == "Tracking" || it.label == "Analysis" || it.label == "Issue"} && !issue.get("labels").size() == 1)) {
return false
}
else if (issue.getAsString("issuetype") == ("Marketing") && (!issue.get("labels")?.any{it.label == "Tracking" || it.label == "New_Feature" || it.label == "Issue"} && !issue.get("labels").size() == 1)) {
return false
}
else return trueThe validation of issuetypes and labels seem to work, but when i add function for counting the number of labels it doesn't work as expected.
0 labels returns true
1 allowed label returns true
1 not allowed label returns true
2+ allowed labels returns true
2+ not allowed labels return true
Any help is much appreciated.