Setting Priority field value based on customfield value

Usage FAQ

On this page

Still need help?

The Atlassian Community is here for you.

Ask the community

Please note that adding Javascript to custom fields is a customisation and not maintained as a supported part of JIRA.

tip/resting Created with Sketch.

Check the comments below. This page has been flagged as outdated.

 

As the users are neglecting the description of the Priority field, a more detail custom field is created to represent the Priority field. Depending on the radio button custom field selected, the Priority field value is set.

  1. Create a customfield name "Severity" at Browse >> Administration >> Issue Fields >> Custom Fields
  2. Configure the radio button custom field to have a field options
  3. Check the customfield ID in the Customfield table from the database by using the following SQL query:

    SELECT id FROM customfield WHERE cfname="Severity";
    
  4. Modify the following javascript code so that <id>will be replaced with the id of the custom field found from the first step:

    <script type="text/javascript" charset="utf-8" id="priorityCustomFieldScript">
        function setIssuePriorityAndSubmit(e)
        {
            // set the value of the priority field here:
    	if(document.getElementById("customfield_<id>_1").checked)
    	{
    		document.getElementById("priority").selectedIndex = 0;
    	}
    	else if(document.getElementById("customfield_<id>_2").checked)
    	{
    		document.getElementById("priority").selectedIndex = 1;
    	}
    	else if(document.getElementById("customfield_<id>_3").checked)
    	{
    		document.getElementById("priority").selectedIndex = 2;
    	}
    	else if(document.getElementById("customfield_<id>_4").checked)
    	{
    		document.getElementById("priority").selectedIndex = 3;
    	}
    	else if(document.getElementById("customfield_<id>_5").checked)
    	{
    		document.getElementById("priority").selectedIndex = 4;
    	}
        }
    
        function hidePriorityAndAddSeverityHook()
        {
    	var row = document.getElementById("priorityFieldArea");
    	row.style.display = 'none';
    
    	AJS.$("#customfield_<id>_1").parents('form').submit(setIssuePriorityAndSubmit);
        }
    
        var currentLocation = window.location.href;
        if (currentLocation.indexOf('CreateIssue') > -1 || currentLocation.indexOf('EditIssue') > -1) {
            AJS.$(document).ready(hidePriorityAndAddSeverityHook);
        }
    </script>
    
  5. Paste the javascript into the description of the "Severity" customfield at Browse >> Administration >> Issue Fields >> Custom Fields.

There is no need to hide or remove the 'Priority' field from the screen. The javascript code will hide the Priority field by itself.

Last modified on Dec 2, 2011

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.