Hello,
I have 2 separate Scripted Fields on a Sub-task. These fields are reading existing data from a custom field on the parent issue.
Field 1 on Sub-task (Parent Prod Start Date). This field reads a custom date field from the parent issue and displays it on the sub-task.
Field 2 on Sub-Tasks (Parent DBA Estimate). This field reads a custom numeric field from the parent issue and displays it on the sub-task.
Both of these scripted fields is generating errors in the logs during a re-indexing and also when a user is working on a parent issue.
error - javax.script.ScriptException: java.lang.NullPointerException: Cannot invoke method getCustomFieldValue() on null object. A stacktrace has been logged.
--------------------------------------
Here is the code for Parent Prod Start Date -
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.component.ComponentAccessor;
def field = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Prod Install Start Date/Time")
def abc456 = issue.parentObject.getCustomFieldValue(field);
return abc456;
Here is the code for Parent DBA Estimate -
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.component.ComponentAccessor;
def field = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("DBA Estimate")
def abc123 = issue.parentObject.getCustomFieldValue(field);
return abc123;
--------------------------------------------
Here is the complete error -
2014-08-05 08:45:32,448 ajp-bio-8009-exec-17 ERROR ahughes 525x6851x1 vihicd 1.1.1.1 /plugins/servlet/com.onresolve.ScriptedFieldPreviewServlet [onresolve.jira.groovy.GroovyCustomField] javax.script.ScriptException: java.lang.NullPointerException: Cannot invoke method getCustomFieldValue() on null object
Nic is correct as usual, but I don't think that's the problem.
I did a quick test and it seems like jira requests the value of the custom field even when it's not in the context. I don't know why... I think there is a reported bug for this in jamieechlin.atlassian.net/browse/GRV but it's not fixed, because I'm not sure what I can do. I need to reproduce and report to Atlassian.
In the meantime I would do:
if (issue.isSubTask()) {
...
return something
}
return null
This can happen when either
In both cases, wrapping the "getCustomFieldObject" call in "if field not null" type if blocks should fix it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Nic,
I am not able to get the logic correct for checking against the "if field not null". Do you have an example of the syntax?
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Argh, sorry, I've made a mistake
Most of your code is actually ok, and, for the record, this is what I do to avoid empty field errors:
CustomField budgetField = customFieldManager.getCustomFieldObjectByName(budgetFieldName); def thisPaidCR = issue.getCustomFieldValue(paidDaysField) if ( thisPaidCR ) { total += thisPaidCR }
But although that will catch the error I thought you're getting, I have looked in the wrong place.
You have:
issue.parentObject.getCustomFieldValue(field);
The problem is not "getCustomFieldValue", it's "parentObject". That is returning a null.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, it is on the parent object where the null error is coming.
i tried to verify there is a valid field on the parent, however it is still generating the same issue.
Here is the new code, that still doesn't work
def field = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Prod Install Start Date/Time")
def abc456 = issue.parentObject.getCustomFieldValue(field);
def total = "Hello";
if (abc456 != null)
{
total = (abc456)
}
return total;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, I have a thought - could you try
def abc456 = issue.parentObject().getCustomFieldValue(field);
I think parentObject is a method, not a field, so we need ()
p.s. I still apologise for looking in completely the wrong place at first, I feel like I owe you a pint or something to make up for wasting your time!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried -
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.component.ComponentAccessor;
field = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Prod Install Start Date/Time")
def abc456 = issue.getParentObject().getCustomFieldValue(field);
if (issue.isSubTask())
{
return abc456
}
return null;
however it is still not working for the parent issue
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm not sure it can work for the parent issue - by definition, they won't have a parent themselves, and, if I have understood your config, they won't have the field either. I'd move the "def abc456" inside the "if (issue.isSubTask())" block, then it won't try to retreive the parent or the field when there's nothing there.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you!
moving that in seems to have taken care of the error -
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.component.ComponentAccessor;
field = ComponentAccessor.getCustomFieldManager().getCustomFieldObject('customfield_11401')
if (issue.isSubTask())
{
def abc456 = issue.getParentObject().getCustomFieldValue(field);
return abc456
}
return null;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.