Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Make Field Optional Based on Behavior

I would like to make a field optional based on the selection of another field. 

I have ScriptRunner and was trying to use a Behavior. I have a multi-select drop-down field, and if an option is selected, then I want a drop-down field to become optional.

Here's the Behavior server-side script:

def multiSelectField = getFieldByName("My Multi-Select Field")
def  DropDown= getFieldByName("My Drop-Down Field")

def multiSelectvalue = multiSelectField.getValue()

if (multiSelectvalue.toString().contains("Option 3")) {
DropDown.setRequired(false)
}else {
DropDown.setRequired(true)
}

 

When I go the Create screen and select Option 3 in my multiselect field, the drop-down field's required indicator does not change.

Any issues you see? What would another suggested approach be?

 

 

1 answer

0 votes

Fields in Jira are made mandatory at the back-end first.   If you configure a field to be mandatory (by virtue of being one of certain system fields, or with a field configuration that tells the project it is mandatory), then you cannot turn that off by tinkering with it at the browser level, which is what Behaviours does.

So, you need to reverse the question.  It should be "use Behaviours to make a field mandatory when I need it to be"

I tried this in a way. My code looked like this:

def multiSelectField = getFieldByName("My Multi-Select Field")
def  DropDown= getFieldByName("My Drop-Down Field")

def multiSelectvalue = "Option 3" in multiSelectField*.value

if (!multiSelectvalue) {
DropDown.setRequired(true)
}else {
DropDown.setRequired(false)
}

Another way I wrote it:

def multiSelectField = getFieldByName("My Multi-Select Field")
def  DropDown= getFieldByName("My Drop-Down Field")

if (! ('Option 3' in multiSelectField*.value)) {
DropDown.setRequired(true)
}else {
DropDown.setRequired(false)
}

 

In either case, as I'm on the Create Issue screen, it starts out with the Drop Down required (as desired). However, when I select the value in the multi-select, the behavior doesn't change. If I reverse the setRequired settings, it shows the field as optional initially, as I would expect, so there isn't an overwriting field configuration. 

It just seems that when I select the value in the multi-select, perhaps it's not registering it to alter the field behaviour; I'm not sure. 

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

How to log work and track time in Jira when a person is part of multiple teams

  The manager’s daily activities include a list of challenges to reach high levels of efficiency for their teams. Part of these challenges is related to how to deal with the worklog systems sin...

102 views 2 1
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you