Forums

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

How to customise a custom single select list using behaviour

Krishnakumar Parameswaran February 11, 2019

I've a custom field with Select List (single choice) where i want to add / remove values based on issue type.

can someone help me on this ?

Adding my code below :

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.component.ComponentAccessor

def cfManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def multiSelectCF = cfManager.getCustomFieldObjectsByName("Component")[0]
def formMultiSelect = getFieldById("customfield_15200")
def singleSelectValue = getIssueContext().getIssueType().name

def config = ComponentAccessor.fieldConfigSchemeManager.getRelevantConfig(issueContext, multiSelectCF)
def options = optionsManager.getOptions(config)

def Bug = ["A","B"]

def Story = ["B","D"]

def Epic = ["A","B","C","D"]

switch(singleSelectValue)
{
case "Bug":
formMultiSelect.setFieldOptions(options.findAll{it.value in Bug}.collectEntries{[(it.optionId): it.value]})
break
case "Story":
formMultiSelect.setFieldOptions(options.findAll{it.value in Story}.collectEntries{[(it.optionId): it.value]})
break
case "Epic":
formMultiSelect.setFieldOptions(options.findAll{it.value in Epic}.collectEntries{[(it.optionId): it.value]})
break
default:
formMultiSelect.setFieldOptions(options)
}

Thanks,

Krishna

1 answer

0 votes
Payne
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.
February 11, 2019

Looks like you're heading down the right path; what are you experiencing that indicates that it is not working as you expect?

Krishnakumar Parameswaran February 12, 2019

Hi  @Payne ,

 

Thanks for responding. 

Actually i fixed it myself after some digging up.

There was another behaviour for the Component field. which created dependency for the field.

So i merged the both codes. Now its working as expected.

 

Regards,

Krishna

Suggest an answer

Log in or Sign up to answer