NullPointerException when getting custom field value post function

pooja chourasia December 6, 2017

Using below code for a custom field which is also a required field( Single Choice list), still getting below error, Need help !!

Code: 

<Field Name> <% out << issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObjectByName("<Field Name> ") %>

 

Error:

java.lang.NullPointerException

       at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:1003)

       at com.atlassian.jira.issue.Issue$getCustomFieldValue$0.call(Unknown Source)

       at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)

       at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:110)

       at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:122)

       at groovy.tmp.templates.GStringTemplateScript5$_getTemplate_closure1.doCall(GStringTemplateScript5.groovy:15)

       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

       at java.lang.reflect.Method.invoke(Unknown Source)

       at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)

       at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:324)

       at

       at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)

       at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)

       at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

       at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

       at java.lang.Thread.run(Unknown Source)

1 answer

0 votes
Alexey Matveev
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.
December 6, 2017

Hello, 

The problem is that your variable componentManager is unknown.

it shoud be 

issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("<Field Name> "))

But you would need to make an import

import com.atlassian.jira.component.ComponentAccessor

pooja chourasia December 6, 2017

Thanks Alexey, Could you please suggest that how can we import library in the email section. 

NullPointerException.PNG

Alexey Matveev
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.
December 6, 2017

<Field Name> <% out << issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("<Field Name> ")) %>

 

pooja chourasia December 6, 2017

Tried, still getting the same error.

Please if you can suggest more solutions.

Thanks in Advance.

Alexey Matveev
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.
December 6, 2017

What do you pass for <Field Name> ? Make sure the field really exists

pooja chourasia December 6, 2017

Required Order Contract Term (in months): <% out << issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Required Order Contract Term (in months)")) %>

 

Required Order Contract Term (in months) -  It's a field

Alexey Matveev
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.
December 6, 2017

Somehow the field is not found in your Jira instance. Or the error is actually different

pooja chourasia December 7, 2017

Hello Alexey

The issue was with the field only, re-indexing has fixed this issue.

Many Many Thanks for Your help :)

Alexey Matveev
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.
December 7, 2017

Nice to hear. Good luck.

Suggest an answer

Log in or Sign up to answer