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

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,560,647
Community Members
 
Community Events
185
Community Groups

Get Value of Cascading Select on Screen

I have a screen with a cascading select list called "Root Cause", if the second list = to "Cannot Reproduce" I want to set the Resolution field to "Cannot Reproduce" automatically for the user. I'm having trouble with reading the values in the Root Cause field though. I'm using Behaviours in Script Runner to accomplish this. I have the script on the Root Cause field. 

import com.atlassian.jira.component.ComponentAccessor
import static com.atlassian.jira.issue.IssueFieldConstants.RESOLUTION

def rootCause = getFieldByName("Root Cause")
def rcVal = rootCause.getFormValue() as Map

if (rcVal.get("1") == "Cannot Reproduce")
{
//This part works, the if statement doesn't
def constantsManager = ComponentAccessor.constantsManager
def allowedResolutions = constantsManager.resolutions.findAll
{
it.name in ["Cannot Reproduce"]
}

getFieldById(RESOLUTION).setFieldOptions(allowedResolutions)
}

 

2 answers

1 accepted

2 votes
Answer accepted
Roland Holban (Adaptavist)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Aug 14, 2018 • edited

The script is correctly on the Root Cause field but it has some mistakes:

  • To get the value of a field use getValue()
  • To set the value of a field use setFormValue() and not setFieldOptions()
    • setFieldOptions() is used to set the available options for fields such as checkboxes or radio buttons

      Take a look at the Behaviours API to see available methods.

  • You can access the resolutions from the ResolutionManager and not the ConstantsManager

Correct script:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.ResolutionManager

def resolutionManager = ComponentAccessor.getComponent(ResolutionManager)
def resolutionToSet = resolutionManager.getResolutionByName("RESOLUTION_NAME")

def resolutionField = getFieldById("resolution")

def selectListField = getFieldById(fieldChanged)
def selectListValue = selectListField.value

if (selectListValue.size() > 1 && selectListValue[1] == "SELECT_LIST_OPTION_NAME") {
resolutionField.setFormValue(resolutionToSet.id)
}

@Roland Holban (Adaptavist)

Thanks for the update to set the resolution, but Behaviours doesn't like

selectlistValue.size() and selectListValue[1] 

Note, the Root Cause field is a Cascading Select List..

behaiour 1.pngbehaiour 2.pngbehaiour 3.png

Roland Holban (Adaptavist)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Aug 14, 2018

Dont worry about those errors. The static type checker cant always correctly infer variables types. You can read more about it here: https://scriptrunner.adaptavist.com/latest/jira/#_static_type_checking

Also, I changed the script a bit. Make sure you grab the new one.

Awesome.. Thank you. That worked perfectly.

I am getting "cannot invoke method size on null object"?

I cannot seem to get the value of my Multi Select list? 

Hi ,

I have a behavior where I am trying to copy values from Select List (cascading) field to a Text field. But after several attempts its not working, 

Can you suggest a solution to get values of both dropdown of Select List (cascading) to a text field ?

Thanks !

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events