Forums

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

Set project Category to Select list field

sanjay
Contributor
April 18, 2025

Hello Team,

I have one manupulated list of Category and I want to set this list as a single select options in Select list field on Radio button trigger using behaviour.

I tried to get basic details using below code :

import com.atlassian.jira.project.ProjectCategory
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.customfields.option.Options
import com.atlassian.jira.issue.customfields.impl.SelectCFType

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

def confirmation = getFieldById(getFieldChanged())  // Radio button field

def confirmationValue = confirmation.getValue()

def categoryField = getFieldByName("Item Type")  /Select List Field
def projectCategoryManager = ComponentAccessor.getProjectManager()
 
Collection < ProjectCategory > projectCategories = projectCategoryManager.getAllProjectCategories()
 
def customFieldManager = ComponentAccessor.getCustomFieldManager()

def optionsManager = ComponentAccessor.optionsManager

def categoryList = []
if (confirmationValue == "Yes") {
    if (projectCategories) {
        projectCategories.each {
            category -> if (category != null && category.getName() != null) {
               
            }
            if (category.getName().containsIgnoreCase("jagile")) {
                categoryList.add(category.name)
            }
        }

    }

}


1 answer

0 votes
Salih Tuç
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.
April 19, 2025

Instead of that, you can use a Custom Picker field.

  • Go to ScriptRunner -> Fields
  • Create a "Custom picker"
  • In the configuration script, paste your code which returns the categoryList


This would work. By the way, maybe it is because of the copy-pasting but check the following code; it seems the second if should be inside of the first if statement:

category -> if (category != null && category.getName() != null) {
if (category.getName().containsIgnoreCase("jagile")) {
categoryList.add(category.name)
}
}

Also, if you insist on using this kind of filtering; you need to store all options inside the field's possible values and then depend on the `categoryList` you should update this option list.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events