Forums

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

Filter selectable "Fix Version/s" field values

Christoph Moser
August 16, 2018

Hi Guys,

how could one filter the selectable values of the "Fix Version/s" field by a filter which is different for each project? (Filtercriteria could e.g. be a value of some custom field, or a category)

Also the displayed name of the versions should be adapted (e.g. remove prefixes)

 

Example:

Project A has the versions

Pref1_1.1_x
Pref1_1.2_y
Pref2_3.2_z
Pref2_4.1

now based on a filter only versions with prefix "Pref1" should be shown, the displayed names of the versions should miss the prefix - so this versions would be the result:

1.1_x
1.2_y

Kind regards, Christoph

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 Champions.
August 16, 2018

Hello,

There is no option like this. What are you trying to do? Are you developing your own plugin for Jira?

Christoph Moser
August 16, 2018

I wanted to do this with a behaviour ... some projects has tons of versions which should be filtered to make it easier to choose.

 

Some colleague meant to maybe solve this with a custom field (multiselect) which gets filled when loading the edit screen... but this seamed to be a bad hack.

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 Champions.
August 16, 2018

Do you mean ScriptRunner behaviour?

Christoph Moser
August 16, 2018

Yes - ScriptRunner

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 Champions.
August 16, 2018

I think it is possible to limit Fix Versions with ScriptRunner behaviour, but I was not able to find any code.

You can try to use the solution of your colleague or you can try the Power Scripts add-on. There is a similair feature to behaviours, called Live Fields. 

You code would look like this:

lfRestrictSelectOptions("fixVersions", {"Version1", "Version2"}); 

Christoph Moser
August 17, 2018

Temporary I solved it with a custom field (multiselect) which get filled with all possible values in one script.

Another script filters the shown Options.

 

BUT: We really should consider Power Scripts because the actual workaround has about 100 lines of code

Christoph Moser
August 28, 2018

I don't know if there is a better way of filtering the versions in the fixVersions field with ScriptRunner.

(We additionally have the problem that the "Configuration Management Toolkit" plugin also filters the versions - but with another filter)

So finally I found a "dark hack".

If one sets the description of a field it can be done with html with an <script></script> tag in it... the script gets executed.

 

import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField

class FixVersionsFilter extends FieldBehaviours {
def run() {
def piVersionsRegex = "/^sws.*/i"
FormField fixVersionField = getFieldById("fixVersions")
fixVersionField.setDescription(
"<html>" +
" <body>" +
" <div></div>" +
" <script type=\"text/javascript\">" +
" var onChange = function(element, callback) {" +
" var HTML = element.innerHTML;" +
" var debounce = false;" +
" window.setInterval(function() {" +
" var newHTML = element.innerHTML;" +
" if (HTML !== newHTML) {" +
" debounce = true;" +
" HTML = newHTML;" +
" } else if (debounce && HTML === newHTML) {" +
" debounce = false;" +
" callback();" +
" }" +
" }, 500);" +
" };" +
" var filterFixVersions = function() {" +
" var releasedVersion = \$(\"#fixVersions>optgroup[label='Released Versions']>option\");" +
" for(var i = 0; i < releasedVersion.length; ++i){" +
" if (${piVersionsRegex}.test(releasedVersion[i].text)){" +
" releasedVersion[i].remove();" +
" }" +
" }" +
" var optionsUnreleased = \$(\"#fixVersions>optgroup[label='Unreleased Versions']>option\");" +
" for(var i = 0; i < optionsUnreleased.length; ++i){" +
" if (${piVersionsRegex}.test(optionsUnreleased[i].text)){" +
" optionsUnreleased[i].remove();" +
" }" +
" }" +
" };" +
" \$(document).ready(function(){" +
" filterFixVersions();" +
" var fixVersionsElement = \$(\"#fixVersions\")[0];" +
" onChange(fixVersionsElement, function() {" +
" filterFixVersions();" +
" });" +
" });" +
" </script>" +
" </body>" +
"</html>"
)
}
}

Suggest an answer

Log in or Sign up to answer