Simplify Your Workflow with Script-Runner: Show/Hide Fields with Behaviour Functionality

adminUncategorized

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 critical severity…

Luckily the Script Runner for JIRA provides ‘Behaviors’. 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 the 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 of what the behavior add-on provides:

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

To implement the behavior above, take the following steps:

  • Access the behavior menu under Administration – Add-ons

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 custom field id’s are retrieved by accessing the custom field configuration screen and looking at the URL…

  • Done – have a bar of chocolate 😉

Further Reading

Check out the document on the Adaptavist site: here.

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.