Making field conditionally required

Here's my situation. I have Field A and Field B. I have a script that I've written that will display Field B if Field A equals a certain value. What I need to do (and haven't gotten anything to work yet) is make Field B required if it pops up. My javascript is shown below, any help with this is greatly appreciated!


<script type="text/javascript">

jQuery(document).ready(function($) {
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) {

function callShowHideFunctions(){
$('#customfieldA').change(function() {

function showHidefields(){

if($("#customfieldA option:selected").val() == 'xxx'){


1 answer

1 accepted

Hi Nick,

This can be achieved using the Behaviours module of the Script Runner plugin.

I have attached below a sample script which can be applied as a behaviour to Select List Field A in order to make Select List Field B visible and required when a certain option is selected in Select List Field A.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserUtil
// Get pointers to the custom field(s) required
def cf = getFieldByName("Select List A")
def cf1 = getFieldByName("Select List B")

// Get the Value of Select List A
def cfVal = cf.getValue().toString()

// Hide Select List B by default

// If option B is selected in Select List A show Select List B and make it required
if(cfVal == "B"){
    cf1.setHidden(false) // Show Select List B
    cf1.setRequired(true) // Make Select List B Required

I hope this helps


Thanks a lot Kristian!! That works great!

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Oct 11, 2018 in Marketplace Apps

You + one app + a desert island...

Hi all! My name is Miles and I work on the Marketplace team. We’re looking for better ways to recommend and suggest apps that are truly crowd favorites, so of course we wanted to poll the Community. ...

3,457 views 6 6
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