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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

JIRA Script Runner Groovy cascade custom field get parent options by index or child options by index

Edited
Ramakrishnan Srinivasan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jan 23, 2019

Hi,

I need some help in Custom Cascade Field, 

 I have created a Cascade Custom Field with

  • parent options = 'Jan-19' , 'Feb-19', 'Mar-19'
  • child options = '0%', '25%', '50%', '75%', '100%'

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

 

2 answers

1 accepted

1 vote
Answer accepted
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jan 23, 2019

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

Ramakrishnan Srinivasan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jan 23, 2019

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"
}
}
Like # people like this
Ramakrishnan Srinivasan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jan 23, 2019

In addition, if you want the custom field object by name

//def cascSelectCf = customFieldManager.getCustomFieldObject("customfield_14510")
def cascSelectCf = customFieldManager.getCustomFieldObjectByName("MyCustomFieldName")
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jan 24, 2019

Also, you can use below code instead of adding/removing "," characters

it.getChildOptions().collect {"${it.value}"}.join(",")

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.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events