Velocity Template to Filter off of null custom fields

Brandon Kreiens April 6, 2018

Hi all,

 

I've got a customized release notes template that for a specific project, only displays the contents of a custom field called release notes instead of the standard issue key and description.

The code works great, except that if there's an issue in the release with no value in that custom field, it just displays an empty bullet point. I've been trying to find the right code so that if that custom field is empty/null it just gets skipped, but everything I've tried somehow isn't working. 

Any tips?

 

Here's my current code. My guess is that I need to either slightly modify line 5 or add something in front of line 33 that is along the lines of

#if ($issue.getCustomFieldValue("customfield_11600").length() >0)) 

 

But everything I've tried there doesn't work. 

 

release note code.png

Thanks!
Brandon

 

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.
April 7, 2018

Try like this

#if ($issue.getCustomFieldValue("customfield_11600") != null) 

Brandon Kreiens April 9, 2018

Thanks Alexey! I tried that, but I get an error now when I open up the release notes.

Do I need to call something at the top of my .vm to use null? Or any other thoughts on why it's breaking for me?

 

An error occurred whilst rendering this message. Please contact the administrators, and inform them of this bug. Details: ------- org.apache.velocity.exception.ParseErrorException: Encountered "null" at templates/jira/project/releasenotes/releasenotes-html-Copy.vm[line 33, column 89] Was expecting one of: "[" ... "{" ... "(" ... <STRING_LITERAL> ... "true" ... "false" ... <INTEGER_LITERAL> ... <FLOATING_POINT_LITERAL> ... <IDENTIFIER> ... "{" ... <LOGICAL_NOT> ... at org.apache.velocity.Template.process(Template.java:141) at 

Like Aleksandr Oliferuk likes this
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.
April 9, 2018

Could you try like this:

#if (! $issue.getCustomFieldValue("customfield_11600")) 

Brandon Kreiens April 9, 2018

No luck. It still gives me the empty bullet points:

 

bullet points.png

Suggest an answer

Log in or Sign up to answer