Use the behaviour functionality of the script runner to show/hide fields

rootUncategorized2 Comments

 

You can’t imagine what Atlassian JIRA allows you to track. To accommodate all potential reporting needs, large companies tend to expand the number of fields on forms. In a number of cases, fields are only relevant under particular conditions.   Making users understand the logic behind these fields and dependencies is in many cases a daunting task.  Try to explain that the effectiveness review field must be entered in case of a high impact issue with a medium to a critical severity …

Luckily the Script Runner for JIRA provides ‘Behaviours’. A behavior defines how fields behave for issues in a given project or issue context. Some examples of behaviors are:

  • Making a field mandatory depending on other data entered on the issue screen (i.e during an issue creation or an issue transition)
  • Making a field read-only dependent on user role or group
  • Doing server-side validation of field data, before the issue screen is submitted
  • Setting a field value dependent on other issue screen data

A small example what the behavior add-on provides

Configuring behaviors might seem a bit rough in the beginning but once you understand how to setup such behavior, very neat things can be done.

To implement the behavior above take following steps

  • Access the behavior menu under Administration – Addons

image2016-3-30-23_23_5

  • Create a new behavior

image2016-3-30-23_25_33

  • Add a field to the behavior
    In this case, the behavior is triggered by changes in the drop down field

image2016-3-30-23_27_52

  • Now define what should happen when the field is changed by a user, by adding a server side script

image2016-3-30-23_32_49

  • Add the script itself
    In this case the script should show a text field (condition A, condition B) depending on the selected drop down value

 

def dropDown = getFieldById("customfield_10500")
def conditionA = getFieldById("customfield_10501")
def conditionB = getFieldById("customfield_10502")
log.debug("dropdown value" + dropDown.getValue())
 
if (dropDown.getValue() == "a") {
    conditionA.setHidden(false);
    conditionB.setHidden(true);
} else {
    conditionA.setHidden(true);
    conditionB.setHidden(false);
     
}

The customfield id’s are retrieved by accessing the custom field configuration screen and look at the URL …

  • Done – have a chocolate

Further Reading

Check out the document on the Adaptavist site:
https://scriptrunner.adaptavist.com/latest/jira/behaviours-overview.html

The script runner has endless possibilities to customize your JIRA to your operating environment. Want to know more, don’t hesitate to attend the ‘automate your processes with JIRA’ event on April 14.