It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Hide options in cascade select field - Behaviour Script Runner

Hi,

 

How to hide few options from cascade field (parent option) based on issue type.

I am using the below script.

 

import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.customfields.manager.OptionsManager;

def reqtype = getFieldById("customfield_A")
def job = getFieldById("customfield_B")
def customField = customFieldManager.getCustomFieldObject("customfield_B")
def config = customField.getRelevantConfig(getIssueContext())
OptionsManager optionsManager = ComponentAccessor.getOptionsManager();
def options = optionsManager.getOptions(config)
// Set the values inside the select list field
//def ParticipationTypeMap = [null: "None"]
def ParticipationTypeMap = [:]
ParticipationTypeMap.put("-1", "None")
if(reqtype.getValue() == "1")
{
job.setFieldOptions(options.findAll {it.value in ['value1', 'VALUE 2']})

}
else if(reqtype.getValue() == "2")
{

ParticipationTypeMap += options.findAll{it.value in ['value3', 'value4']}.collectEntries {[(it.optionId.toString()): it.value]
}

job.setFieldOptions(ParticipationTypeMap);

}

 

Please let me know how to hide an option from the field.

 

Thanks,

Krithica

1 answer

1 accepted

1 vote
Answer accepted

Hi Krithica,

Here is a snippet of the code that I have used previously with Behaviours:

List<String> optionsA = ["ValueA", "ValueB"]
def cf1 = getFieldByName("CustomField_A")

def customField = getCustomFieldManager().getCustomFieldObjectByName("CustomField_A")
OptionsManager optionsManager = ComponentAccessor.getOptionsManager()
FieldConfig config = customField.getRelevantConfig(getIssueContext())
Options options = optionsManager.getOptions(config)
cf1.setFieldOptions(options.findAll { it.value in optionsA })

If you wanted to keep the None value when setting the options for a customfield then put the string "None" in your list of options. 

This code is not working for me. I want to set parent field options for cascade select list.

Apologies that was for a Standard select list not cascading.

I have made some changes to your code, please select the field 'reqtype' in the Behaviours section, and add this server side script:

 

import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.customfields.manager.OptionsManager;

def reqtype = getFieldById(getFieldChanged())
def job = getFieldById("customfield_B")

def customField = customFieldManager.getCustomFieldObject("customfield_B")
def config = customField.getRelevantConfig(getIssueContext())
OptionsManager optionsManager = ComponentAccessor.getOptionsManager();
def options = optionsManager.getOptions(config)

// Set the values inside the select list field
def ParticipationTypeMap = [:]
ParticipationTypeMap.put("-1", "None")

if(reqtype.getValue().equals("1"))
{
ParticipationTypeMap += options.findAll {it.value in ['value1', 'VALUE 2']}.collectEntries {[it.optionId.toString()): it.value]}

}
else if(reqtype.getValue().equals("2"))
{
ParticipationTypeMap += options.findAll{it.value in ['value3', 'value4']}.collectEntries {[(it.optionId.toString()): it.value]}
}

job.setFieldOptions(ParticipationTypeMap);

}

 

Thanks so much it works.

How would I hide options in the *child* list?

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira

The add-in you’ve been waiting for: Jira Cloud for Excel 🙌

Introducing Jira Cloud for Excel Here at the product integrations team at Atlassian, we are thrilled to announce the new Jira Cloud for Excel add-in! This add-in lets you export Jira data directly ...

883 views 7 24
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you