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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It is working for me as well. There are 2 coding errors, here is the same code corrected
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);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Peter Newton it is working for me as well. I need it for only IT View but not for portal view. is there any way?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.