Script Runner - error in Setting Cascading Select values - error using code example

Lotus Support October 19, 2017

Untitled.png

When i am trying to update cascade field "Category" using your example i get errors adn it doesnt work

 

def optionsManager = ComponentAccessor.getOptionsManager() def c

ustomFieldManager = ComponentAccessor.getCustomFieldManager() def fieldName = "Category" def field = getFieldByName(fieldName) def customField = customFieldManager.getCustomFieldObjectByName(fieldName) def fieldConfig = customField.getRelevantConfig(getIssueContext()) def options = optionsManager.getOptions(fieldConfig) def parentOption = options.find {it.value == "A"} def childOption = parentOption?.childOptions?.find {it.value == "A1"} field.setFormValue([parentOption.optionId, childOption.optionId])

1 answer

0 votes
Daniel Yelamos [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.
October 20, 2017

Hi hreich.

Could you kindly state what is the error or errors that you are getting/

Cheers

Dyelamos

Lotus Support October 21, 2017

I am missing importers but aince i am noob i dont know which ones

Daniel Yelamos [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.
October 23, 2017

You are only missing one:

import com.atlassian.jira.component.ComponentAccessor

def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def fieldName = "Category"
def field = getFieldByName(fieldName)
def customField = customFieldManager.getCustomFieldObjectByName(fieldName)
def fieldConfig = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(fieldConfig)
def parentOption = options.find {it.value == "A"}
def childOption = parentOption?.childOptions?.find {it.value == "A1"}
field.setFormValue([parentOption.optionId, childOption.optionId])

 This should work.

Cheers!

Dyelamos

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events