Forums

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

How to get Scriptable Custom Version Picker to display "None"?

Tim Snyder February 10, 2018

The builtin "Affects Version" field will display "None" when it is EMPTY.

 

I've successfully created a Scripted Custom Field called "Released Fix Versions" that will display the values in FixVersions that are marked released (this is to help users to see which fixVersions should be available to them without having to understand how Jira tracks releases).

 

I have the following code:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.version.VersionManager
import com.atlassian.jira.project.version.Version
import java.util.Collection


Collection<Version> releasedFixVersions = []

for (i in issue.fixVersions) {
if (i.isReleased()) {
releasedFixVersions.add(i)
}
}
return releasedFixVersions

 

This seems to be working great.  I get a nicely formatted list of version links when there is at least one released FixVersion.  However, when there aren't any released FixVersions, the field is displayed as just empty.  I'd prefer that it display 'None'.  I played around with returning different things when the list is empty, like:

return releasedFixVersions ? releasedFixVersions : null  // same whitespace behavior
return releasedFixVersions ? releasedFixVersions : ["None"]  // same whitespace behavior
return releasedFixVersions ? releasedFixVersions : ["None" as Version]  // error about not being able to coerce String into Version... okay, that's reasonable

 

Is there some magic I can return that will get the "Version Picker" template to display "None"?  Please include a pointer into where the "Version Picker" template is in the Jira source if you know.

 

Thanks!

1 answer

0 votes
Ivan Tovbin
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.
February 10, 2018

Hi Tim,

As you probably know, a custom field is always hidden from issue view unless it has a value set. There's a an open feature request here regarding this very behaviour. 

Since you are using a 'Version Picker' template for your custom field, the expected value for this field is an array of 'version' objects, that's why nothing is happening when you are trying to pass it an array of 'strings' for example. 

Having said all of the above I suppose the most straighforward solution, even if not the most elegant one, is to create a version literally named "None" and then pass it to your field in the event when you want the field to look empty.

Tim Snyder February 12, 2018

Thanks @Ivan Tovbin.  I didn't know that custom fields are hidden when they don't have a value.  If the field was hidden, would I see the field name on the screen? I'm asking because the custom field shows up, I see the field name, it just renders the empty list as whitespace.

Your idea about a version called None might work.  I could just release it before my project began and archive it so that it only gets used when my custom field script ends up with an empty list.

Ivan Tovbin
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.
February 12, 2018

The reason why your custom field is still displayed even if it's seemingly empty is as follows:

Like I said, the expected value of a 'Version picker' type field is an array of 'version objects'. It means that the field will always have a value - an array, regardless of that array itself being empty or not. For your field to have no value at all you have to:

return null

 Hope this helps.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events