You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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
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)
}
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try writing to log by adding log.debug(parentFieldValue) to check whether the field is captured or not.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This script works for me as described by @Ravi Sagar _Sparxsys_ , 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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hello @Ravi Sagar _Sparxsys_ ,
Getting the error while using the script that you suggested above. Please assist
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.