Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Changing field value based on cascading first value

Rajeswari Thangavel
Contributor
June 21, 2018

Hello,

 

I am trying to update select field(responsibleSquad) value based on the value selected in cascading first value ("UC Services")

I found no error. But it is not working as expected. Am I missing something?

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.customfields.view.CustomFieldParams

def responsibleSquad = getFieldById("customfield_13605")

def optionsManager = ComponentAccessor.getOptionsManager()

def customFieldB = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Responsible Squad")
def fieldConfigB = customFieldB.getRelevantConfig(getIssueContext())
def optionsB = optionsManager.getOptions(fieldConfigB)
def optionBI = optionsB.find {it.value == "Experience Development Squad"}
def optionBII = optionsB.find {it.value == "Adobe Platform"}
def optionBIII = optionsB.find {it.value == "Analytics & Insight"}

Object value = getCustomFieldValue("UC Services")
CustomFieldParams params = (CustomFieldParams) value
if (params != null) {
Object parent = params.getFirstValueForNullKey()
Object child = params.getFirstValueForKey("1")

if (parent.toString() == "Web Personalisation - Brand") {
responsibleSquad.setFormValue(optionBI.optionId)
}
else if (parent.toString() == "Lifecycle Comms") {
responsibleSquad.setFormValue(optionBII.optionId)
}
else if (parent.toString() == "Event-Based Trigger Comms") {
responsibleSquad.setFormValue(optionBIII.optionId)
}
}

 

1 answer

1 accepted

0 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.
June 25, 2018

Are you doing this in a behaviour?

Rajeswari Thangavel
Contributor
June 25, 2018
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.
June 26, 2018

Here is an example of setting the value of a single select list based on the parent value of a cascading select list in a behaviour:

import com.atlassian.jira.component.ComponentAccessor

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

def cascadeListName = "cascade_list_name"
def cascadeList = getFieldByName(cascadeListName)
def parentValue = cascadeList.value[0]
def childValue = cascadeList.value[1]

def selectListName = "select_list_name"
def selectList = getFieldByName(selectListName)
def selectListCF = customFieldManager.getCustomFieldObjectsByName(selectListName)[0]
def selectListFieldConfig = selectListCF.getRelevantConfig(issueContext)

def options = optionsManager.getOptions(selectListFieldConfig)
def optionToSet = options.find {it.value == "option_name"}

if (parentValue == "something") {
selectList.setFormValue(optionToSet.optionId)

 You can follow the outline of this code and modify it to suit your needs.

Rajeswari Thangavel
Contributor
June 26, 2018

@Roland Holban (Adaptavist)

 

It works. Thanks a lot

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.
June 26, 2018

Youre welcome!

Suggest an answer

Log in or Sign up to answer