Forums

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

Component/s field error when only one Component

Jozef Vandenmooter
Contributor
May 6, 2020

We have projects that have multiple Components and others that only have 1. The Component/s field is required in all projects because they all share the same Field Configuration.

When creating a new issue in a project that only has 1 Component and the user does not click on that one Component, an error is received stating that the field is required. That's pretty silly. Is there an easy way to prevent that? (easier than writing a Behaviour script with ScriptRunner I mean).

This is on Jira Server 8.5.1

Capture.PNG

1 answer

1 accepted

0 votes
Answer accepted
Jozef Vandenmooter
Contributor
May 10, 2020

Ok, there's four "solutions" to this.

  1. Change the Renderer of the Component/s field from Select List to Autocomplete. The field is then initially blank which is more intuitive; 
  2. Create an additional set of screens, screen schemes and field configurations and an additional screen configuration and field configuration scheme where the Component/s field is not used and not Required;
  3. Create an additional set of field configurations and an additional field configuration scheme where the Component/s field is set to Hidden;
  4. Create a Behaviour Initializer that sets the value of the Component/s field to the sole value that's in the Project's Components list and hide it from the user. Map the Behaviour to those projects that only have one Component.

I decided to go with option #4, to avoid having to create additional configurations:

import com.atlassian.jira.component.ComponentAccessor

def componentField = getFieldById("components")
def projectComponentManager = ComponentAccessor.getProjectComponentManager()
def components = projectComponentManager.findAllForProject(issueContext.projectObject.id)

componentField.setFormValue(components[0].id)
componentField.setHidden(true)

Suggest an answer

Log in or Sign up to answer