Hi Guys,
I am trying to set Cascading select list field description based on Parent Value using Script Runner behaviour . Not giving any error and not updating the description of the field. Kindly suggest where am i doing wrong. I have tried script avaiable at this link :- https://library.adaptavist.com/entity/set-a-default-option-on-a-cascading-select-list
It's also not working for me.
Tried to apply at script at intilizer as well as on field . On both case not working.
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
// the cascading select field that you want to set
final fieldName = 'Activity'
// parent value that you want to select
final parentValue = 'RFP Creation & Distribution'
// child value that you want to select
final childValue = 'RFP Request sent to GOSS'
def field = getFieldByName(fieldName)
def optionsManager = ComponentAccessor.optionsManager
def customField = ComponentAccessor.customFieldManager.getCustomFieldObjects(issueContext.projectId, issueContext.issueTypeId).findByName(fieldName)
def fieldConfig = customField.getRelevantConfig(issueContext)
def options = optionsManager.getOptions(fieldConfig)
if (options.find { it.value == parentValue }){
field.setDescription("Start typing to get a list of possible users")
}
Community moderators have prevented the ability to post new answers.
If you are not actually setting default values in the same script, you don't need to bring in the optionsManager or anything after that.
Here is a full script that shows how you can work with cascading select:
def fld = getFieldById(fieldChanged)
def parentValue = 'Something special'
if(!fld.value){
fld.setDescription("Make a parent selection")
} else {
if(fld.value[0]==parentValue){
if(fld.value.size()==1){
fld.setDescription("You have found the special parent value of ${fld.value[0]}. Now make a selection in the second-level")
} else {
fld.setDescription("Bravo! You have selected ${fld.value[0]}-${fld.value[1]}")
}
} else {
if(fld.value.size()==1){
fld.setDescription("You've made a boring selection of ${fld.value[0]}")
} else {
fld.setDescription("You've made a boring selection of ${fld.value[0]} and ${fld.value[1]}")
}
}
}
A couple of pointers...
Cascading select in behaviours always return ArrayList<String>
Hi @PD Sheehan Thanks for sharing code for cascading field. It works for me :)
Cascading field works very different from other field, i hadn't tried nor think of nested if for cascading field. Thanks a lot Mate!
Learn new thing from you. :)
fld.value.size()==1 ( 1 for parent field right ? ) .
fld.value[0] ( [0] for parent field ? )
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
fld.value.size() can be either 0, 1, or 2
Then, you use [0] or [1] to access either the first or second value. But attempting to access these values when they don't exist will give you an error:
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.