Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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

Set Cascading Select list field description based on Parent option using Script Runner behaviour

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")
}

 

1 answer

1 accepted

1 vote
Answer accepted

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>

  • If you've selected nothing, the array list is size 0: [ ]
  • If you've only selected the parent value, the list is size 1: [ParentValueString]
    • If you try to access fld.value[1] you will get an error
  • If you've selected both values size = 2: [ParentValueString, SecondLevelString]

Hi @Peter-Dave 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!

Hi @Vikrant Yadav 

fld.value.size() can be either 0, 1, or 2

  • fld.value.size()==0 //this means both values are "none"
  • fld.value.size()==1 //this means only parent level is selected
  • fld.value.size()==2 //this mean both level are selected

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:

  • fld.value[0] //this reuturn the selected parent-level value
  • fld.value[1] //this returned the selected second-sevel value
Like Vikrant Yadav likes this

Thanks a lot @Peter-Dave Sheehan  

Have a Great Day!

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