Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

JIRA 7 - Disable/Enable Cascade Select Parent Option programmatically

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.
January 25, 2019

Hi,

 I need some help in disabling Cascading Select Parent Options by running the script monthly once.

Lets say I have two cascade select fields

Field 1 with parent options 'Dec'-19', 'Jan-19', 'Feb-19','Mar-19

Field 2 with parent options ' 'Dec'-19', 'Jan-19', 'Feb-19','Mar-19

Requirement is 

  • Field 1, except for Dec-19, I want to disable all other options
  • Field 2 except for Jan-19, I want to disable all other options
  • Next month, I have to Disable and Enable sliding month names
    • FIeld 1 - disable Dec-19, enable Jan-19
    • Field 2 - disable Jan-19, enable Feb-19

I was exploring Script Runner, python jira REST for past couple of days, but could not find a way of doing. I have to do this monthly once so that I can make users do what I want them to do from that month onwards 

Thank you in advance, any help/pointers is appreciated

with warm regards

ramki

 

 

1 answer

1 accepted

0 votes
Answer accepted
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.
January 25, 2019

As soon as I posted and searched again, Thanks to Mark Markov, I got the answer from https://community.atlassian.com/t5/Jira-questions/Disable-particular-options-with-groovy-script-runner/qaq-p/871249

I am also adding a small additional feature here which is to check whether the option is disabled or not ( I was searching for it and found again today :) )

//https://community.atlassian.com/t5/Jira-questions/Disable-particular-options-with-groovy-script-runner/qaq-p/871249
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.getCustomFieldObjectByName("DUMMY_ONE")
// get an issue just for relevant config
def issue = issueManager.getIssueObject("PROJ-1")
Options options = optionsManager.getOptions(cascSelectCf.getRelevantConfig(issue));
def rootOptions = options.getRootOptions()
rootOptions.each {

if(it.getDisabled() == false) {
log.info "Option is disabled"
}
if(it.value == "Dec-18") {
//log.info "$it.optionId - $it.value"
optionsManager.disableOption( it)
//optionsManager.enableOption( it)
}
}

 All the time I was searching to disable cascade select option, this time I just searched disable options and hit the jackpot

Mario Carabelli
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.
January 25, 2019

Interesting usecase. Thank you for posting the solution you found. You should nark your own solution as tge accepted one, so that people know that the problem is solved😊

With kind regards

Mario

Srikanth Ganipisetty
Contributor
March 25, 2022

If it's a cascading field, it will disable the root options, not the child options. You need to update your code to catch the child options and then perform disabled/enabled. 

Thanks,

Srikanth Ganipisetty

Suggest an answer

Log in or Sign up to answer