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

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);

}

 

Like Rodolfo So likes this

Thanks so much it works.

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

Hi Carlos,

Did you find a solution for this?

I want to hide values for child options me too.

It is not currently possible to restrain the child list of a cascading list through groovy - in the end we used two separate select lists (i.e. non-cascading).

A Script Runner behaviour (triggered when the parent list is updated) was used to constrain the child list - switch on the different parent options using an IF/case statement & then you can set the desired list options on the other (child) select list.

-> you will need to consider what you want to display when the form first loads. Should the child list be empty until the user selects an option in the parent list? If so, this can again be achieved through a Behaviour using the 'Initialiser' property 

Thanks Carlos for info.

Suggest an answer

Log in or Sign up to answer
TAGS

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