Forums

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

getting null pointer exception in logs.

Jyotsna Chimakurthi November 1, 2022

I am getting "java.lang.NullPointerException: Cannot invoke method getCustomFieldValue() on null object " error for the below script.

Please help to how to resolve the issue.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.label.LabelManager
import static com.atlassian.jira.issue.IssueFieldConstants.*

def issueManager = ComponentAccessor.getIssueManager()
def contextIssue = issueManager.getIssueObject(getContextIssueId())
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def epicLinkCf = customFieldManager.getCustomFieldObjectsByName("Epic Link").first()
def linkedEpic = contextIssue.getCustomFieldValue(epicLinkCf) as Issue
LabelManager labelManager = ComponentAccessor.getComponent(LabelManager)
def labels = labelManager.getLabels(contextIssue.id)

if (getBehaviourContextId() == "FEA") {

getFieldById("summary").setFormValue("${contextIssue.summary}")
getFieldById("issuelinks-linktype").setFormValue("delivers")
getFieldById("issuelinks-issues").setFormValue(contextIssue.key)

if ((linkedEpic) != null)
{
getFieldByName("Epic Link").setFormValue(linkedEpic.key)
}
def values = []

labels.each { values.add(it.getLabel()) }

def labelField = getFieldById(LABELS)

labelField.setFormValue(values)
}

1 answer

0 votes
Nir Haimov
Community Champion
November 2, 2022

Hi @Jyotsna Chimakurthi 

Try to change:

def epicLinkCf = customFieldManager.getCustomFieldObjectsByName("Epic Link").first()

To:

def epicLinkCf = customFieldManager.getCustomFieldObjectByName("Epic Link")

also, make sure you have the "Epic Link" field in the issue it fails on... 

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, loom, loom for training, loom for teaching, video training, async learning, online education, screen recording, loom tutorials, loom use cases, atlassian learning, team training tools, instructional video, virtual training tools

🛗 Elevate Your Training and Enablement with Loom

Join us June 26, 11am PT for a webinar with Atlassian Champion Robert Hean & Loom’s Brittany Soinski. Hear tips, stories, and get your burning questions answered. Learn how Loom makes training and enablement easier. Don’t miss it!

Register today
AUG Leaders

Atlassian Community Events