Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×Hello,
During the screen creation, I need to hide certain values of a selectlist based on issuetype.
I search on Atlassian community and I found this script written by Kristian Walker:
I tried but I got a message to inform me that getIssueContext() is deprecated.
I'm newbie on scripting ^^
Could you help me to rearrange to script with my requirements?
Replace getissuetypeobject().name by getissuetypeId in order to use issuetype id and not the name
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.* // Get the current issue type from the issue context incase the issue // has not been created yet def issuetype = getIssueContext().getIssueTypeObject().name // Get a pointer to my select field def selectcf = getFieldByName("DemoSelectList2") // Get pointers to the required custom field and otion managers def customFieldManager = ComponentAccessor.getCustomFieldManager() def optionsManager = ComponentAccessor.getOptionsManager() def customField = customFieldManager.getCustomFieldObject(selectcf.getFieldId()) def config = customField.getRelevantConfig(getIssueContext()) def options = optionsManager.getOptions(config) // If issue type matches change the cf values to be displayed if (issuetype.contains("Story")) { def optionsMap = options.findAll { it.value in ["A", "B"] // list of options you want to show }.collectEntries { [ (it.optionId.toString()): it.value ] } selectcf.setFieldOptions(optionsMap) }
Thanks a lot.
Cedric
How to hide only one value from the custom field.?
Regards
From a select list?
If yes, to hide 1 value, the tips is to select values you want to show and not hide unwanted value
here a example:
You want to hide Value C
if (issuetype == "63" || issuetype == "10402" || issuetype == "11301") {
def optionsMap = options.findAll {
it.value in ["Value A", "Value B", "Value D"] // list of options you want to show
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
selectcf.setFieldOptions(optionsMap)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Cedric,
in-stead of hiding one value i thought to make one value to be default for one issue type alone.
So i wrote the script for the same.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.*
// Get the current issue type from the issue context incase the issue
// has not been created yet
def issuetype = getIssueContext().getIssueType().name
// Get a pointer to my select field
def selectcf = getFieldByName("Discovery Method")
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObject(selectcf.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
if (issuetype.contains("In-Sprint Bug")) {
def optionToSelect = options.find { it.value == "Unit Test" }
selectcf.setFormValue(optionToSelect.optionId)
}
But i cannot make one value to be default. Any idea on this ? how to make one particular value to default.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Saravanan,
I think you need more an initialiser
https://scriptrunner.adaptavist.com/latest/jira/behaviours-overview.html
it's talk about how to initialise the description.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I couldn't find the proper method to use it. It would be great if you help me out. Please
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Cedric_DEVAUX Does it working for you. Underlyingissue shows the issue type name but it is not setting the values based on issue type.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Cedric_DEVAUX @Alexey Matveev
Its working if we do not have any context root. How to read the values from context root for the fields.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You should change
getIssueContext().getIssueTypeObject().name
to
underlyingIssue?.getIssueType().name
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.