Disable issue type javascript

Hi,

I've  updated my JIRA instance in from 6.3.15 to 6.4.6.

I used a script to disable some issue type with javascript for group of people on the issue creation screen, but my script doesn't work anymore and I don't understand why.

 

jQuery(document).ready(function($) 
        {    
            JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function(e,context) {   
                $("#issuetype option").each(function()  {  
                    if( $(this).text().trim() == "Type1" || $(this).text().trim() == "Type2")
                        {    
                         $(this).remove();        
                        }                    
                });    
            });
        });
 }

 

It seems that this script is not executed.

It worked perfectly in 6.3.15.

Has anybody an idea?

 

Thank you

6 answers

1 vote
Stephen Deutsch Community Champion Jun 24, 2015

We just recently upgraded to 6.4 and I had to figure it out as well. It seems like the select has been replaced with a single-select that pulls the information from another source, so this is what I did to remove the issue types. It's not so elegant, but at least it works OK. It should actually work on 6.3 as well.

jQuery(document).ready(function() {
  var removeIssueType = function() {
    jQuery("a[title='type1']").parent().hide();
    jQuery("a[title='type2']").parent().hide();
  }
  var findIssueType = function() {
    jQuery("span.drop-menu").click(removeIssueType);
    jQuery("#issuetype-field").keyup(removeIssueType);
    jQuery("#issuetype-field").click(function() {
      setTimeout(removeIssueType, 1);
    });
    jQuery("#project").change(function() {
      setTimeout(findIssueType, 1000);
    });
  }
  if (AJS.params.loggedInUser !== "allowed.user") {
    JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function(e,context) {
      findIssueType();
    });
    setTimeout(findIssueType, 500);
  }
});

That should be enough to get you started for any customizations.  Just replace "type1" and "type2" with the types you want to remove.

we have JIRA 7.0.2, but script is not working correctly, I am doing any mistake,Please let me know,

Thank you for the help.

jQuery(document).ready(function() {
  var removeIssueType = function() {
    jQuery("a[title='Core Patch Request']").parent().hide();
    jQuery("a[title='Customization Patch Request']").parent().hide();
  }
  var findIssueType = function() {
    jQuery("span.drop-menu").click(removeIssueType);
    jQuery("#issuetype-field").keyup(removeIssueType);
    jQuery("#issuetype-field").click(function() {
      setTimeout(removeIssueType, 1);
    });
    jQuery("#project").change(function() {
      setTimeout(findIssueType, 1000);
    });
  }
      JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function(e,context) {
      findIssueType();
    });
    setTimeout(findIssueType, 500);
});
Stephen Deutsch Community Champion Apr 01, 2016

Yeah, sorry, I guess I never updated it since they removed the title element sometime during the 6.4 development process.  This version should work (just tested it with the latest version of JIRA Cloud):

<script>
jQuery(document).ready(function() {
  var removeIssueType = function() {
    jQuery(".aui-list-item-link").filter(function(){ 
	  return jQuery(this).text() === "Core Patch Request" || jQuery(this).text() === "Customization Patch Request" 
	}).parent().hide();
  }
  var findIssueType = function() {
    jQuery("span.drop-menu").click(removeIssueType);
    jQuery("#issuetype-field").keyup(removeIssueType);
    jQuery("#issuetype-field").click(function() {
      setTimeout(removeIssueType, 1);
    });
    jQuery("#project").change(function() {
      setTimeout(findIssueType, 1000);
    });
  }
  JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function(e,context) {
    findIssueType();
  });
  setTimeout(findIssueType, 500);
});
</script>

Hey, @Stephen Deutsch is there a possibility to use project category instead of project name ? Like there are many projects which needs to hide few issuetypes and needs to be hidden based on category. Thank you so much.

It seems that the <select id='issuetype' has disapeared...

I don't know how to adapt my script. I only find div

This is because Atlassian switched to AUI Select 2 component :

&lt;div class="aui-list" id="issuetype-suggestions" tabindex="-1" style="display: block;"&gt;
    &lt;div class="aui-list-scroll" tabindex="-1"&gt;
        &lt;ul class="aui-last"&gt;
            &lt;li class="aui-list-item aui-list-item-li-bug active"&gt;&lt;a class="aui-list-item-link aui-iconised-link" href="#" title="Bug"&gt;&lt;img class="icon" alt="" src="..."&gt;Bug&lt;/a&gt;&lt;/li&gt;
            &lt;li class="aui-list-item aui-list-item-li-epic"&gt;&lt;a class="aui-list-item-link aui-iconised-link" href="#" title="Epic"&gt;&lt;img class="icon" alt="" src="..."&gt;Epic&lt;/a&gt;&lt;/li&gt;
            &lt;li class="aui-list-item aui-list-item-li-technical-task"&gt;&lt;a class="aui-list-item-link aui-iconised-link" href="#" title="Technical Task"&gt;&lt;img class="icon" alt="" src="..."&gt;Technical Task&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
    &lt;/div&gt;
&lt;/div&gt;

You have to adapt your code and remove the aui-list-item element corresponding to the issue type you want to remove, they all have a specific class: 

aui-list-item-li-bug
aui-list-item-li-epi

etc ..

Beware though, this element is appended to the DOM when the user focus the issue type select.

Hi,

thank you for your answers. I'll test it tomorrow and give you my feed back.

 

Hi it works fine, thank you very much for your help!!

I am facing the same problem. Can i have sample code snippet please.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Sunday in Agility

You asked for it, so we delivered: images on issues have arrived

A picture tells a thousand words. And agility boards have just released their latest feature: cover images on issues – so now your board can tell a story at first glance. Upload attachmen...

184 views 1 11
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you