Scriptrunner Post-Function cannot locate custom field's value

Reid Bourgeois March 23, 2023

Hi, 

 

I have multiple declarations pulling in numeric values into a post-function. They all work excluding one; I am getting this error: 

 

2023-03-23 15:13:04,837 ERROR [workflow.AbstractScriptWorkflowFunction]: Workflow script has failed on issue ABC-123 for user 'rbourg'.

View here: http://[site URL]/secure/admin/workflows/ViewWorkflowTransition.jspa?workflowMode=live&workflowName=[workflow name]=postfunctions&workflowTransition=1&highlight=26 java.lang.NullPointerException:

Cannot invoke method getValue() on null object at Script90.run(Script90.groovy:55)

 

Here's the variable declaration, that is written the exact same way as other variables that are working as expected. 

 

def Datafeed = cfManager.getCustomFieldObjects(issue).findByName("Datafeeds Hours").getValue(issue) as Double
Here's what I've tried to troubleshoot this error: 
1) Added a default value of 0 to ensure that the field is not null (within Jira's custom field manager).  
2) Ensured that the casing and spacing of "Datafeeds Hours" is correct. 
3) Added the following script to the code after the variable declaration: 
if (Datafeed == null)
{
  Datafeed = 0
}
As mentioned, all of the other variable declarations work as expected. Any insight as to why this is occurring?  

 

 

1 answer

0 votes
Radek Dostál
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.
March 24, 2023

Don't look for anything mysterious in the API, it works, so it is most definitely an issue somewhere in the name and/or field's visibility for the issue. Maybe it contains a space at the end, maybe it contains unprintable unicode. It should be possible to list the fields such as

for (def cf : cfManager.getCustomFieldObjects(issue))
log.warn("DEBUG - field='" + cf.getName() + "'"

and then confirming the name is in that list at all to begin with, if it is, whether it has any extra spaces. This won't show unprintable characters, but if you can prove that the name is identical to an eye, then you know there is a "hidden" difference in characters. I've seen plenty null bytes in all sort of places that beg the question of how do people even paste so many of them.

 

I'm not familiar with 'findByName' - I assume it works, and it reads to me that you're saying it works elsewhere, so not going to doubt it. If you haven't verified that method, you could try plain old groovy syntax such as

cfManager.getCustomFieldObjects(issue).find { it.getName() == "Datafeeds Hours" }

Although they should work the same in theory I assume.

 

If you see the same name, no extra spaces and whatnot, and it still doesn't work, it would be interesting to see the hex value of the name if it contains something splendid, e.g. by dumping it from the db to a hexeditor.

Suggest an answer

Log in or Sign up to answer