Hi,
I need some help in Custom Cascade Field,
I have created a Cascade Custom Field with
I know that for parent option, 'None' is one of the options.
I know how to get the value of selected parent option like
Map p1m0 = getCustomFieldValue("MyCustomFieldName") as Map
monthName = p1m0.get(null)
But how do I get all options of parent select list by their index like index0=None, index1='Jan-19', index2='Feb-19' ...
Even if user selects None, I have to return an indexed parent option to another calculated field based on which month we are in
Similarly how do I get all child options of this cascade custom field and access them by their index. I went through multiple posts but could get this through
Thank you in advance
with warm regards
ramki
Hello ramki,
Below is the code to get root (parent) options for a cascaded custom field.
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.customfields.option.Options
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
// change xxxx with id of your cascaded custom field
def cascSelectCf = customFieldManager.getCustomFieldObject("customfield_xxxxx")
// get an issue just for relevant config
def issue = issueManager.getIssueObject("XYZ-123")
Options options = optionsManager.getOptions(cascSelectCf.getRelevantConfig(issue));
def rootOptions = options.getRootOptions()
rootOptions.each {
log.info "$it.optionId - $it.value"
}
Hope it helps
Excellent, thank you Tuncay Senturk,
With your help, in addition to your code, I also found the way to get the Child options
String childOptions = ""
rootOptions.eachWithIndex {it,index->
if(index == 0) {
it.getChildOptions().each {
childOptions += "$it.value"+","
}
//to remove the last comma in childOptions string
//https://www.leveluplunch.com/groovy/examples/remove-last-character-from-string/
//be aware, there was a space after comma above and I wasted time :)
childOptions = childOptions[0..-2]
monthName = "$it.value"
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In addition, if you want the custom field object by name
//def cascSelectCf = customFieldManager.getCustomFieldObject("customfield_14510")
def cascSelectCf = customFieldManager.getCustomFieldObjectByName("MyCustomFieldName")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Also, you can use below code instead of adding/removing "," characters
it.getChildOptions().collect {
"${it.value}"
}.join(
","
)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
While looking for solutions to my problem I came across your post.
Please help me solve my problem, because I do not master groovy scripts :
Indeed on my cascading custom field, I want to purge the selection list of child options when creating the issue (transition "to create") .
Cordially.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Join us to learn how your team can stay fully engaged in meetings without worrying about writing everything down. Dive into Loom's newest feature, Loom AI for meetings, which automatically takes notes and tracks action items.
Register today!Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.