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

Next challenges

Recent achievements

Recognition

  • Give kudos
  • My kudos

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to remove options from a multi version picker field ?

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

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,

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 ?

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 .

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!

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,

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 ?

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

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

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 ?

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

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 ?

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

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.

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

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

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.

Dont know why its not working in my jira

tried even on a new Jira 5.0 :(

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.

&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

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.

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.

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 ;)

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

Ah at last that option is removed :)

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

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

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

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 ?

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

$(this).text()

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

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

Use any one of the following
$(this).find("option:selected").text();

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

dbconfig.xml

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
Community showcase
Published in Confluence Cloud

Share your Confluence Cloud experience for a chance to win $500!

Take our 5-minute survey to win a $500 Visa gift card! Are you currently using Confluence Cloud? We want to hear from you! Fill out this quick survey about your Confluence Cloud experience so we ...

136 views 1 8
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you