Show custom fileds based on other custom field value on CREATE ISSUE screen

I'm implementing a help desk in JIRA where I have two drop downs - both 'single value select' forCategory and Sub-category.

For example, I have following Categories:

  • Content Development
  • Events
  • Design

And each category has a list of sub-categories within them. For example, Design will have following list of options

  • Event Collateral
  • Branding
  • Business Cards

By default, ONLY Category dropdown should be displayed on the CREATE ISSUE screen. When user selects one of the categories, corresponding sub-category drop-down should be displayed on the CREATE ISSUE screen AND that sub-category dropdown should be MANDATORY field.

I looked up for possible solution at the following links:

The first two links basically suggests the same solution - that is to put a JAVASCRIPT in the description field of the custom field and the same is suggested on many other blogs on this issue. They all give this very same example.

However this is not working for me. When I put any JAVASCRIPT in the description of the custom-field, it runs immediately upon saving - on the Field Configuration screen. For example, I just put a following JAVASCRIPT in the description and I got the alert right away (on the Field Configuration screen).

<script type="text/javascript">
alert('hi');
 </script>

However, I do not get any alert on the CREATE ISSUE screen. So, not sure if I am missing anything here. Please advise if I'm looking in the right direction.

The 3rd link, suggests to create a plugin from the JIRA machine. However, I do not have access to that machine, I just have admin access to JIRA.

Is there any feasible way to achieve it via default JIRA configurations/external plugins which are ready-to-use?

My JIRA version is: 6.1.4

Regards,

Rumit

2 answers

1 accepted

Accepted Answer
1 vote

just put the following code on announcement banner for testing

&lt;script type="text/javascript"&gt;

    JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) {

        alert("Hello!!!");

    });

&lt;/script&gt;

 

no need machine permission to deploy plugin, if you have admin access you can update plugin through JIRA Admin UI, following doc explains how to upload addon

https://confluence.atlassian.com/display/UPM/Installing+add-ons

 

Thank you Prasad. This approach might work I believe and I might go in the right direction now.

 

However, the JIRA.Events.NEW_CONTENT_ADDED does not fire if I change the dropdown options. I have to either click CREATE or do some other 'server' event to fire it. 

Also, this approach might not work to 'show' the element. As the java script would be able to show/hide only those controls which are already rendered on the page. I'm also looking for a way to have the fields available on CREATE ISSUE screen, but only visible via my custom logic.

check the answer i posted on following link in your question https://answers.atlassian.com/questions/217176/show-hide-custom-field-depend-on-another-custom-field-value it will fire all the events you no need click on create button! the field should be there on the create screen then only we can hide/show that field, you can add field to create screen, check the following docs https://confluence.atlassian.com/display/JIRA/Defining+a+Screen https://confluence.atlassian.com/display/JIRA/Configuring+Fields+and+Screens

Thank you Prasad. Your solution worked for the Show-Hide logic.

I looked for the solutions to make those sub-categories fields Mandatory and learnt that I could use JIRA Behavior Plugin. I actually used that and put the following script:

 

 

FormField category = getFieldById("customfield_11480");
String categoryVal = category.getValue();
FormField contentDev = getFieldById("'customfield_11481");
contentDev.setRequired(categoryVal == "Content Development");
FormField events = getFieldById("'customfield_11482");
events.setRequired(categoryVal == "Events");
FormField design = getFieldById("'customfield_11483");
design.setRequired(categoryVal == "Design");
FormField web = getFieldById("'customfield_11484");
web.setRequired(categoryVal == "Web");

 

The fields do get a '*' sign so they are set to Mandatory. However, whenever I try to CREATE the issue, I get 'Please wait a moment for the server to finish then retry your action' error pop-up. It looks like an existing issue with JIRA - JBHV-154.

NOTE: I've tried code with and without semicolon and still get the issue;

Can you please suggest anything here? If not Behaviour plugin, is there any other way to make the fields mandatory?

 

Rumit, sorry, i don't have any idea on Behavior plugin, other options are 1. you can develop your own validator using jira api, check following doc to know how to develop validator http://www.j-tricks.com/tutorials/workflow-validator 2. using java script you can do front end validation!

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Sep 18, 2018 in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

20,520 views 2 7
Join discussion

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