Forums

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

Console - NullPointerException: Cannot invoke method getFieldIdByName() on null object

Bhabtosh Panda
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 3, 2020

I am writing a script for the below format.

There are two options. Once we select any data from option one the 2nd option will show the dependency data as per the option one. I am getting null object error.

 

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

final singleSelectName = 'Some Single Select'
final selectName = 'Other Single or Multi Select'

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

def singleSelectField = cfManager.getCustomFieldObjectsByName(selectName)[20]
def formSingleSelect = getFieldByName(singleSelectName)
def singleSelectValue = formSingleSelect?.value
def formSelect = getFieldByName(selectName)

if (!formSingleSelect && !formSelect) {
return
}

def config = ComponentAccessor.fieldConfigSchemeManager.getRelevantConfig(issueContext, singleSelectField)

def options = optionsManager.getOptions(config)

def optionSet1 = [
'Option 1',
'Option 2',
'Option 3',
'Option 4'
]
def optionSet2 = [
'Option 2',
'Option 3',
'Option 4'
]
def optionSet3 = [
'Option 2',
'Option 4'
]

if (!options) {
return
}

switch (singleSelectValue) {
case 'Single Select Option 1':
formSelect.setFieldOptions(options.findAll { it.value in optionSet1 }.collectEntries {
[(it.optionId): it.value]
})
break
case 'Single Select Option 2':
formSelect.setFieldOptions(options.findAll { it.value in optionSet2 }.collectEntries {
[(it.optionId): it.value]
})
break
case 'Single Select Option 3':
formSelect.setFieldOptions(options.findAll { it.value in optionSet3 }.collectEntries {
[(it.optionId): it.value]
})
break
default:
formSelect.setFieldOptions(options)
}

 

 

 

Error is ********************

 

 

java.lang.NullPointerException: Cannot invoke method getFieldIdByName() on null object at com.onresolve.jira.groovy.user.FieldBehaviours.getFieldByName(FieldBehaviours.groovy:74) at Script56.run(Script56.groovy:14)

 

 

Log is *******************

2020-11-03 18:08:06,372 ERROR [common.UserScriptEndpoint]: ************************************************************************************* 2020-11-03 18:08:06,373 ERROR [common.UserScriptEndpoint]: Script console script failed: java.lang.NullPointerException: Cannot invoke method getFieldIdByName() on null object at com.onresolve.jira.groovy.user.FieldBehaviours.getFieldByName(FieldBehaviours.groovy:74) at Script56.run(Script56.groovy:14)

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events