How can I make component/s single value only?

clem
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.
March 26, 2015

How can I make component's single select?

3 answers

1 accepted

3 votes
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 26, 2015

You can't natively.  Options though:

  1. Use a validator to refuse entry of more than one (there are several plugins on the marketplace that can provide that validator).  I'd avoid that one, as it's ugly for the users
  2. Hack the "edit" field template for component so that it is only single select.  Neat, but you have to maintain it in upgrades etc
  3. Use the Script-Runner Behaviour plugin to amend the field type 
  4. Write your own javascript to amend the field type.

I'm not averse to option 2 if you need a global change, but it does add testing burden to your upgrades.  Option 3 is probably the best one.

 

Raju Kadam May 15, 2018

As follow up to Nic's answer, I'm listing here how one can do using Script Runner Behavior

import com.atlassian.jira.bc.project.component.ProjectComponent
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours behaviours

def components = getFieldById("components").getValue() as List<ProjectComponent>
if (components.size() > 1){
getFieldById("components").setError("Please select only one component related to your work.")
}
else{
getFieldById("components").clearError()
}

Hope that helps to anyone who still looking for easy way to get it done for specific project.

Like # people like this
Alex Gallien
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.
March 18, 2021

Thanks for sharing that code Raju! Saved me the time to figure it out myself :)

Like Cyril Egan likes this
0 votes
Massimo Prevignano July 17, 2016

I added a solution for the JIRA version 6.4.13 in the ticket

 JRA-12543 - Need ability to change project component field type from multi select to single selectCLOSED ,

hope it helps.

0 votes
clem
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.
March 26, 2015

Anybody know what the script would be to check if component has more than one entry?

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 26, 2015

What type of script?

Lacey McDonnell November 10, 2016

Groovy / Script Runner

Suggest an answer

Log in or Sign up to answer