Hello Commity,
I am tring to restrict a checkbox field name "Flagged" to allow upto 2 values on create screen. The following script is working for when user select 2 options and throwing error if they select more than 2 values.
But script is aslo throwing error if they seclect 1 value and not select any value.
looking for some help to optimize it.
import static com.atlassian.jira.issue.IssueFieldConstants.*
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
def field = getFieldById(getFieldChanged())
def ComponentsField = getFieldByName("Flagged")
def selectedValues = field.getValue() as List<String>
if (selectedValues.size() <= 2){
ComponentsField.setValid(true)
ComponentsField.clearError()
}
else
//if (selectedValues.size() > 2)
{
ComponentsField.setValid(false)
ComponentsField.setError("Maximum 2")
}