Very useful example to get the values of a cascading customfield using Groovy in Jira.

...
import com.atlassian.jira.issue.customfields.view.CustomFieldParams
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.customfields.view.CustomFieldParams
import com.atlassian.jira.issue.customfields.impl.CascadingSelectCFType
...
import org.apache.log4j.Category

log.setLevel(org.apache.log4j.Level.DEBUG)
def field = customFieldMananger.getCustomFieldObjectByName("CASCADING_CUSTOMFIELD_NAME")
Object cfVal = issue.getCustomFieldValue(field)

HashMap<String, Option> hashMapEntries = (HashMap<String, Option>) cfVal
if (hashMapEntries != null) {
Option parent = hashMapEntries.get(CascadingSelectCFType.PARENT_KEY)
Option child = hashMapEntries.get(CascadingSelectCFType.CHILD_KEY)
first = parent.toString()
second = child.toString()
log.debug("Cascading values selected: $first - $second")
}

Posted by:.

2 replies on “Jira Groovy example to get values from a CASCADING custom field

  1. 
    def cfModule = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == "Module"}
    
    log.info("Module customField: " + cfModule)
    
    def cFieldValue = sourceIssue.getCustomFieldValue(cfModule)
    
    log.warn("Show cFieldValue " + cFieldValue)
    
     
    
    def parentValue = cFieldValue[null]
    
    def childValue = cFieldValue["1"]
    
    log.warn("Show cFieldValue parentValue " + parentValue)
    
    log.warn("Show cFieldValue childValue " + childValue)
    
    

    Liked by 2 people

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s