Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to set limit in Labels field to only one Label ?

Lokesh
Contributor
June 24, 2020

In Labels field, it allows more than one label to be chosen or created & added.

Instead, wondering if there's a possibility to just allow only one label to be chosen from existing ones or create only one New label

Also, either by System " Labels " field or Custom Labels field, either way, if above limit can be set.

Thoughts & ideas, much appreciated.

TYIA

 

3 answers

0 votes
Lokesh
Contributor
June 30, 2020

Tried below in an behavior, doesn't restrict for one label
Any thoughts much appreciated.

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueManager;
import com.opensymphony.workflow.InvalidInputException;
import org.apache.log4j.Logger


def issueManager = ComponentAccessor.getIssueManager()
def labelsField = underlyingIssue.getLabels()
if (labelsField.size() > 1){
   log.info("Please select only one project in 'Labels' field: " + labelsField)  
 throw new InvalidInputException("Please select only one project in Labels field")
}
0 votes
Hernan Halabi - Elite IT Consulting Group
Community Champion
June 24, 2020

@Lokesh what you can possibly do is to set a condition that checks that the field has a single value. I recall doing that for the components field. That would get the work done but will cause headaches to the users because most likely they won't know why they can't transition the issue. Also, they can transition the ticket with a single value and then add a second value again so it's not the most reliable solution

Lokesh
Contributor
June 24, 2020

@Hernan Halabi - Elite IT Consulting Group Not sure why you related transition may get impacted. Trying to understand a bit. Maybe if Component/s or Labels field is workflow validators, maybe that would be the case. 

Also, wondering how do you set a condition to check for single value ?. By any groovy expression ?

Hernan Halabi - Elite IT Consulting Group
Community Champion
June 25, 2020

I recall using a condition option that checked that, no groovy expression. I believe the option said field has a single value might be part of an app. Most likely JMWE or Jira suite utilities.

Lokesh
Contributor
June 28, 2020

Yes, its from JMWE, but its Validator. This checks during transitions. What's required is whenever Labels field is updated for more than one value, then it should stop user. Instead, prompt with error to include only one value.

Tried something as below in an behavior, but this doesn't seem to work nor log anything.

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption;
import com.atlassian.jira.issue.fields.CustomField;
import com.onresolve.jira.groovy.user.FieldBehaviours;
import com.onresolve.jira.groovy.user.FormField;
import com.opensymphony.workflow.InvalidInputException;
import org.apache.log4j.Logger

def issueManager = ComponentAccessor.getIssueManager()
def labelsField = getFieldByName("Labels").getLabel()
if (labelsField.size() > 1){
InvalidInputException Err = new InvalidInputException("Please select only one project in ' Labels ' field")
log.info("Please select only one project in ' Labels ' field" + labelsField)
throw Err
}

Wondering what's missing here !!

Any clue ?

Hernan Halabi - Elite IT Consulting Group
Community Champion
June 29, 2020

Can't help you with that part, sorry

0 votes
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 24, 2020

No, you can't do this with labels.  It's pretty much the opposite of what they were designed for.

The functionality you describe can be done though - create a custom field of type "select" - you can control the list of options and only allow one to be used (if you want to select many, use a multi-select)

Lokesh
Contributor
June 24, 2020

Select list fields (Single or Multi select) are fixed list fields for an user and need to depend on Admin to add any new options/values

While Labels does allow for adding new options/values, it allows more than one to added into it. 

Required is feature mix of both Select & Labels fields. 

This may require new plugin to develop, if no other way out ?

Like # people like this
gitberg March 22, 2023

Completely agree with Lokesh.
We are sitting with the exact same UseCase.
Users need to be able to create these "On The Fly", but they are only allowed to add 1.

Suggest an answer

Log in or Sign up to answer