I'm looking for a way to display only certain values of a customfield based on the value of a previous customfield. I do not want to hide/show the entire customfield, only limit the values available. Is there a way to achieve this?
import com.atlassian.jira.component.ComponentAccessor
def optionsManager = ComponentAccessor.getOptionsManager()
def cfManager = ComponentAccessor.getCustomFieldManager()
def lobField = getFieldById("LOB:")
def lobProgram = getFieldById("LOB:Programs")
def lobProject = getFieldById("LOB:Project")
def cfLobField = cfManager.getCustomFieldObjectByName("LOB:Programs")
def fcLobField = cfLobField.getRelevantConfig(issueContext)
def lobOptions = optionsManager.getOptions(fcLobField)
def analyzeSet = ["MGV", "BLAST"]
if(lobField.getValue() == "Analyze"){
lobProgram.setFieldOptions(lobOptions.findAll{it.value in analyzeSet}.collectEntries { [(it.optionId).toString() in it.value] })
}
Hi dude
Ill try out in my instance and share you the code .
I have created a behaviour and two custom fields - data base type and data base version
and in the behaviour select the first field based on which the second custom field value should be filtered.This code works out for me try this in your instance and later modify it accordingly.
Cheers ...!
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def picklist8 = getFieldByName("Database Type")
def picklist9 = getFieldByName("Database Versions")
def customField =
customFieldManager.getCustomFieldObject(picklist8.getFieldId()) // Pick list Field that dictates other fields on form based on its value
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
def customField1 =
customFieldManager.getCustomFieldObject(picklist9.getFieldId()) // Pick list Field that dictates other fields on form based on its value
def config1 = customField1.getRelevantConfig(getIssueContext())
def options1 = optionsManager.getOptions(config1)
if (picklist8.getValue() as String == "My SQL") {
def optionsMap8 = options1.findAll
{it.value in ["MySQL 5.5","MySQL 5.7"] // list of options you want to show on Biz Priority Field
}.collectEntries {
[
(it.optionId.toString()) : it.value
]
}
picklist9.setFieldOptions(optionsMap8)
}
else if (picklist8.getValue() as String == "MS SQL"){
def optionsMap8 = options1.findAll{
it.value in ["MSSQL 2014","MSSQL 2016"] // list of options you want to show on Biz Priority Field
}.collectEntries {
[
(it.optionId.toString()) : it.value
]
}
picklist9.setFieldOptions(optionsMap8)
}
else if (picklist8.getValue() as String == "SQL Lite") {
def optionsMap8 = options1.findAll
{
it.value in ["SQL Lite 2.1","SQL Lite 3.0"] // list of options you want to show on Biz Priority Field
}.collectEntries {
[
(it.optionId.toString()) : it.value
]
}
picklist9.setFieldOptions(optionsMap8)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Kevin Johnson I appreciate your assistance. A bit later that day I did get my code working. I'll post my results Monday. I'll also give your code a try and may be effectively code mine.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Below is the code I used.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import com.onresolve.jira.groovy.user.FormField
@BaseScript FieldBehaviours fieldBehaviours
Issue issue = underlyingIssue as Issue
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
FormField lob = getFieldByName("LOB: ")
FormField lobPrograms = getFieldByName("LOB:Programs ")
FormField lobProject = getFieldByName("LOB:Project ")
def lobPrograms2 = customFieldManager.getCustomFieldObjectByName("LOB:Programs ")
def lobProject2 = customFieldManager.getCustomFieldObjectByName("LOB:Project ")
def lobProgramsValue = lobPrograms.getValue()
def lobValue = lob.getValue()
def fieldConfig = lobPrograms2.getRelevantConfig(issue)
def fieldConfig2 = lobProject2.getRelevantConfig(getIssueContext())
def allowedOptions = null
def getOptions = optionsManager.getOptions(fieldConfig)
def getOptions2 = optionsManager.getOptions(fieldConfig2)
if(lobValue=="Option1 || lobValue=="Option2){
lobPrograms.setFieldOptions(getOptions.findAll{
it.value in ["This is to be shown", "This one, too!"]
})}
if(lobValue=="Option1" && lobProgramsValue=="This is to be shown"){
lobProject.setFieldOptions(getOptions.findAll{
it.value in ["This is the third option"]
})}
The first if statement is to change field 2 based on field 1. The second if statement is to change field 3 based on field 1 and 2. I just keep repeating the if statement for each unique change.
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.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.