Forums

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

Behaviours - Trying to hide cascade select options based on Issue Type

MIN_MWO012 December 19, 2023

Dear all,

I'm trying to hide some options of a cascading select field based on the issue type select.

 

I know there is a known issue in the child options but I cannot make the parent option selection work.

 

Here is my code:

 

import static com.atlassian.jira.issue.IssueFieldConstants.ISSUE_TYPE
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.component.ComponentAccessor;


def issue = getFieldById(ISSUE_TYPE)
def issueVal = issue.getValue() as String
def cascSelectListName = 'Component 1'
def selectField = getFieldByName(cascSelectListName)
def selectCustomField = customFieldManager.getCustomFieldObject(selectField.fieldId)
def selectConfig = selectCustomField.getRelevantConfig(issueContext)
def selectOptions = ComponentAccessor.optionsManager.getOptions(selectConfig)


if(issueVal == ("Task"))

{
    def selectAvailableOptions = selectOptions.findAll { it.value in ["Onboarding", "Offboarding"] }

selectField.setFieldOptions(selectAvailableOptions)

}

else if(issueVal == ("Incident"))

{
    def selectAvailableOptions = selectOptions.findAll { it.value in ["value1", "value2"] }

selectField.setFieldOptions(selectAvailableOptions)

}
else if(issueVal == ("Service Request"))

{
    def selectAvailableOptions = selectOptions.findAll { it.value in ["value1", "value2"] }

selectField.setFieldOptions(selectAvailableOptions)

}
Thank you for your help

1 answer

0 votes
Laurie Sciutti
Community Champion
February 21, 2024

Hi @MIN_MWO012 ~ Hopefully you've already figured this out, but if not, have you considered using field contexts rather than code?  Ref:  https://confluence.atlassian.com/adminjiraserver0904/configuring-custom-field-contexts-1188768114.html#Managing+multiple+configuration+schemes 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events