Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you