You are here

How to show/hide a JIRA field based on other field's value

JIRA is indeed one of the best issue tracker in the market. The best thing about this tool which I like is the customizations that you can do in it that too managed from the UI itself. Of course there are lot of things are can be done through the interface but sometimes there could be a possibility that you are looking to implement some behavior in the the interface but couldn't find the right solution.

Today we will discuss one such scenario. For instance you want users to fill up a custom field called "Analysis" only when they select priority as critical. Now to implement this show/hide behavior there is no such configuration you can do. There is one custom field type for creating Cascading Select list in JIRA but that is just to show different values in the child select list based on parent. It is relevant in cases like where you want to capture Country/City but that won't solve our purpose.

The scenario we are looking for can be implemented using a javascript, which is obvious choice for implementing such cases but the question is where should we write is js code? There are various ways of doing it. First you can create a web resource and add it as a plugin in your JIRA instance which is the preferred way but if you are not comfortable then you can also add this code in the description field of your custom field.

The description field supports HTML and Javascript both and the code below will be added in the page when you try to create the issue in JIRA.

  1. <script type="text/javascript">
  2. priority = document.getElementById('priority');
  3. if (priority) {
  4. target = document.getElementById('customfield_10000');
  5. // Hide the target field if priority isn't critical
  6. if (priority.value != 2) target.style.display='none';
  7.  
  8. priority.onchange=function() {
  9. if (this.value == 2) {
  10. target.style.display = '';
  11. target.value="enter message here";
  12. } else {
  13. target.style.display='none';
  14. }
  15. }
  16. }
  17. </script>

Points to remember
1. Modify the ID of the custom field that you want to show/hide in this code. For instance in the above code the ID is 10000, you can find the ID of the custom field when you click on the Configure option for that particular custom field. The ID can then be found in the url.
2. In the above example we are showing the custom field when Priority is equal to Critical, whose value is 2, if you want to do this for some other value, you should also change the number and of course this can be done for any other custom field too. Just modify the code accordingly.