Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to remove options from a multi version picker field ?

Mizan
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 3, 2012

I want to remove some options (based on a rule) from a multiversion picker field . How can this be done ?

Any javascript/groovy script example will be highly appreciated.

I tried to set options to a multiversion picker using Behaviours plugin but at present that is not working, have a look at this issue and this question .Using behaviours plugin to set options to a fields is what i want but since i have to do this as early as possible can some one please guide me on how i can remove option from a multi version picker field.

Suggestions , comments welcomed

Thank you :)

6 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

4 votes
Answer accepted
RambanamP
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 3, 2012

to remove options from version picker(following script is for jira 5.0)

<script type="text/javascript">
jQuery(document).ready(function($) {
removeOption();
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) {
removeOption();
});

function removeOption(){
$("#versions option").each(function() {
if( $(this).val() == 'optionid' || add here condition to remove other options){

$(this).remove();
}
});
}


});
</script>

let me know if you have any questions

Cheers,

Mizan
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 3, 2012

Thanks for your answer . i need a script for 4.3.2 and 4.4.4 . can there be a similar script for these versions of jira ?

Mizan
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 3, 2012

I tried the above script in Jira 5.0 but the options remain same . i pasted the script in the description of a mutliversion picker customfield and provided a valid option id however the option is visible in the field on create issue screen and other screens .

Alex Taylor
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 3, 2012

We're trying the script in JIRA 4.4.4 and it's working perfectly - many thanks for this, we've been puzzling over how to do it for ages!

RambanamP
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 4, 2012

HI Mizan,

it should work on Jira 5.0, can you test weather javascript is loading on create screen by giving some alert and let me know you have any issues.

Cheers,

Mizan
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 4, 2012

Hi Rambanam ,

I gave an alert but the alert appears as soon as i update the script on the field and not on the create issue screen .Do you know why this is happening ?

Dieter
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 4, 2012
Could you try to paste the script in the announcement banner? If it works from there i suppose you have overwritten the description of your custom field in the field configuration so what you edit in the custom field description is ignored on the create screen
RambanamP
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 4, 2012

Mizan,

if you want it work do it as follows and test

1.in create screen seelect the project and issue type

2. come out of create issue popup window and refresh the browser

3. open the create issue popup

now i think it should work

Mizan
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 4, 2012

Hi Dieter ,

When i put a alert in announcement banner , whenever the page reload i see a alert box , what should i do to make the script run normally on create and transition screens for a field ?

RambanamP
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 4, 2012

alternatively add the JavaScript under description of custom field which will be in all issue type create screens

Mizan
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 4, 2012

The customfield is in all issue type create screens , this script works for Alex Taylor as he has mentioned in the above comment

The option id is the version id of the option right ?

RambanamP
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 4, 2012

if it worked cool, yes ur correct option id is the version id.

Dieter
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 4, 2012
Just take the whole script in this answer and copy it 1:1 on the announcement banner This should work for all screens. But since this is dangerous and might affect other screens that uses elements with d version it's safer to put it into the field description of your custom field. since ths didn't work for you you should better change that in the field description within the field configuration since this has higher precedence.
Mizan
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 4, 2012

I pasted the exact script in announcement banner and still it does not work .

i insert the script in the description of the customfield

the script automatically appears in the description of the field in field configuration

Mizan
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 4, 2012

The script in this documentation works properly , Is there something i am missing ?

RambanamP
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 4, 2012

Hi Mizan,

sorry for my one of my previes comment saying like adding javascript under custom field description.

i tested now by adding same javascript under field descption in field configuration it worked fine.

Mizan
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 4, 2012

Dont know why its not working in my jira

Mizan
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 4, 2012

tried even on a new Jira 5.0 :(

Alexej Geldt
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.
January 29, 2015

strange. this doesn't work for me as described. when i use a drop-down box in create issue dialog, there is no JIRA.Events.NEW_CONTENT_ADDED fired for me. AJS.$(document).ready(function() { JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) { alert('more content added'); }); }); using this, the alert is coming up once, when i open create issue dialog. Inside the dialog it never triggers again, when i change any content on the dialog.

3 votes
Jobin Kuruvilla [Adaptavist]
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 3, 2012
&lt;script type="text/javascript"&gt;
AJS.$("#versions option").each(function()    {
	if( AJS.$(this).val() == 'optionId'){  
    	AJS.$(this).remove();
	}
   
});
&lt;/script&gt;

Works for me in 4.4.3

Mizan
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 4, 2012

Hi Jobin ,

Thanks for the script but due to some reason scripts are not running on my Jira . When i give an alert, instead of appearing on the create and transition screens the alert appears as soon as i update the script on the customfield description.

Mizan
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 4, 2012

Now the alert appears on the issue create screen when i save the script in the description of field configuration

&lt;script type="text/javascript"&gt;
AJS.$("#versions option").each(function()    {
    if( AJS.$(this).val() == '10100'){ 
        AJS.$(this).remove();
        alert("HI"+AJS.$(this).val())
    }
    
});
&lt;/script&gt;

On the issue create screen i get an alert "HI10100" but the option exists in the multiversion picker.

Jobin Kuruvilla [Adaptavist]
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 4, 2012

Mizan,

You said a multi version picker. That means it is a custom field? If so, the srcript needs to be slightly changes to use the custom field id instead of #versions.

The above script is to hide the option from 'Fix Version'. See if that is working first ;)

Mizan
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 4, 2012

One more question , instead of OptionId can i check optionName ? if yes how ?

Mizan
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 4, 2012

Ah at last that option is removed :)

Jobin Kuruvilla [Adaptavist]
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 4, 2012

Try AJS.$(this).text() instead of AJS.$(this).val(). Actually, do an alert first as I haven't tried it before ;)

Mizan
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 4, 2012

it works . thanx :) but not able to compare it with the version name eg:if( AJS.$(this).text() == 'test') not working

Mizan
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 5, 2012

( AJS.$(this).text().trim() == 'test') works :)

Mizan
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 25, 2012

Hi Jobin ,

The above script does not work with IE8 (javascript enabled)

&lt;script type="text/javascript"&gt;
AJS.$("#versions option").each(function()    {
    alert("i am in each")
        if( AJS.$(this).val() == '10100'){
        alert("i am in if")
        AJS.$(this).remove();
        alert("HI"+AJS.$(this).val())
    }
     
});
&lt;/script&gt;

i get an alert "i am in each" but not the second alert

the script works fine in FF and Chrome

Can you hlp me with this ?

0 votes
Mizan
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 9, 2013

dbconfig.xml

0 votes
RambanamP
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 20, 2013
Use any one of the following
$(this).find("option:selected").text();

or 
$("#yourdropdownid option:selected").text();

0 votes
Raquel Moracho Sánchez February 20, 2013

Hello

Doing that I get the text of all options concatened, and I'd like to get only the text of the option selected, and for it firstly I need to access the option, and then get the value

Thank you

0 votes
Raquel Moracho Sánchez February 20, 2013

Hello

I wanted to know how can I access to the text of the option instead of its value. Any idea?

for example

<option value='001'>Opción 1</option>

'Opción 1' is the thing I want to recover

Thank you very much

Mizan
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 20, 2013

$(this).text()

If this does not help you should ask a new question .

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events