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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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

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.
Nov 19, 2023 • edited

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.
Nov 21, 2023

Hi @shoshana_uzan

Has your question been answered?

If yes, kindly accept the answer.

Thank you and Kind regards,

Ram

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