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

Scriptrunner Behaviour om a cascading select list field -getFieldById(fieldChanged)

shoshana_uzan November 19, 2023

Hi,

I wrote a script in the behavior environment for a cascade list field
The beginning of the code:

-------------

import com.atlassian.jira.component.ComponentAccessor


def customFieldManager = ComponentAccessor.customFieldManager
def optionsManager = ComponentAccessor.optionsManager

def outcomeField = getFieldById(fieldChanged)

def selectedOptions = outcomeField.getValue() as Map
def ParentOption = selectedOptions.get(0).toString()
def ChildOption = selectedOptions.get(1).toString()

def indicatorsField = getFieldByName("Resource")

// Get the all the options of Indicators
def indicatorsCF = customFieldManager.getCustomFieldObjectsByName("Resource")[0]
def config = indicatorsCF.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
-------------

But the script is executed only when both field values change (the Parent and the Child)

Is there a solution for the script to execute even when only the Parent value of the field changes?

 

Can anyone help me?

Regards, 

Shoshi

1 answer

1 accepted

0 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 19, 2023

Hi @shoshana_uzan

If you want to trigger the Behaviour when the Parent option of the Cascading List is selected, you can use the approach shown in the sample working code below:-

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours behaviours
def sampleCascade = getFieldById(fieldChanged)
def sampleCascadeValue = sampleCascade.value

def sampleText = getFieldByName('Sample Text')
sampleText.formValue = ''

if (sampleCascadeValue == ['Option 1']) {
sampleText.setFormValue("Option 1 Selected")
} else if (sampleCascadeValue == ['Option 2']) {
sampleText.setFormValue("Option 2 Selected")
} else if (sampleCascadeValue == ['Option 3']) {
sampleText.setFormValue("Option 3 Selected")
}

Please note that the sample working code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

Below is a screenshot of the Server-Side Behaviour configuration:-

behaviour_config.png

 

Below are a couple of test screenshots for your reference:-

1. When the Create Issue dialog first loads, no option from the Cascading List is selected. Hence, as expected, the Sample Text Field is not updated either.

test1.png2. If Option 1 is selected from the Parent option of the Cascading Select List, the value in the Text Field is set to Option 1 Selected, as shown below.test2.png

3. If Option 2 is selected from the Parent option of the Cascading Select List, the value in the Text Field is set to Option 2 Selected, as shown below.test3.png

 

4. If Option 1 is selected from the Parent option of the Cascading Select List, the value in the Text Field is set to Option 3 Selected, as shown below.test4.png

I hope this helps to solve your question. :-)

Thank you and Kind regards,

Ram

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 21, 2023

Hi @shoshana_uzan

Has your question been answered?

If yes, kindly accept the answer.

Thank you and Kind regards,

Ram

shoshana_uzan November 29, 2023

Hן @Ram Kumar Aravindakshan _Adaptavist_ 

 

I apologize for the late reply 
I was on an unexpected vacation
Your solution helped me a lot
Thank you

Regards

Shoshana

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events