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

Next challenges

Recent achievements

Recognition

  • Give kudos
  • My kudos

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

How do I gray out the second level of cascading select field?

Hi,

I have a cascading select list, in some of the first level select- there are no second level select, so when the user chooses those ones, the second option he gets is to choose None. This is confusing to the users.

Is there an option to gray out the second level if we didn't insert any options to choose from, instead of presenting a None value.

I want to use a behavior script, but not sure how to.

Thanks,

Dana 

1 answer

0 votes

Hi @dana m 

Try this piece of code.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.fields.config.FieldConfig
import com.atlassian.jira.issue.customfields.option.Options


def parentField = getFieldById("customfield_10501")
def parentFieldValue = parentField.getValue()
def childField = getFieldById("customfield_10501:1")
def childFieldValue = childField.getValue()
def customField = getCustomFieldManager().getCustomFieldObjectsByName("CUSTOM FIELD NAME")
FieldConfig config = customField[0].getRelevantConfig(getIssueContext())
def rootOptions_ = ComponentAccessor.getOptionsManager().getOptions(config)
def childOptions_ = [:]

rootOptions_.rootOptions.each { it ->
childOptions_[it] = it.childOptions
}

def nullcheck = []
nullcheck = childOptions_.findAll { it.value.size() == 0 }.keySet()
def readOnlyYes = nullcheck.findAll { it ==~ parentFieldValue[0].toString() }.size()

if( !parentFieldValue.isEmpty() && readOnlyYes >= 1) {
childField.setReadOnly(true)
} else {
childField.setReadOnly(false)
}
  1. Create a behaviour on the field where you want this to be done.
  2. Add the following code in the server-side script.
  3. Make sure you change the customfield_id at 2 places and CUSTOM FIELD NAME

Let me know if it works.

Ravi

Hi Ravi,

Thanks for your reply and the example script.

Unfortunately it didn't work for me, I mapped the field and project and changed the Customer field ID and name.

Still the second level shows the None regularly.

Any suggestions.

Thanks,

Dana 

The childField should be like this.

def childField = getFieldById("customfield_10501:1")

In the browser do inspect element and confirm the id along with the number after the colon.

Ravi 

I tried this template before but it didn't work,

"customfield_10501:1"

 checking now in the inspect element , i saw another option but tried it and still it's not working, and the None appears in the second level.

Try writing to log by adding log.debug(parentFieldValue) to check whether the field is captured or not.

Jason K I'm New Here Oct 24, 2020

This script works for me as described by @Ravi Sagar _Adaptavist_ , forcing an edit to the cascading select field to open the edit screen (instead of inline) and locking the second dropdown if the only option is "none"/null.  It also works in the create screen.

I'm trying to do something somewhat different, but using this as a springboard.  I wanted to report to others who find this post that it works as described, since it was not marked as accepted. 

It may even be possible to allow inline editing with this script, but I have not tested it and don't intend to.

Thanks!

Suggest an answer

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

5 mobile apps for Jira Cloud to boost productivity

  It’s very important to have access to the workflow process from anywhere. Especially if you manage the work of others. There is no difference whether you’re out of office, or drive a ca...

284 views 2 5
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