Disable particular options with groovy script runner

Dennis S_
Contributor
August 20, 2018

Hi everybody,

 

I want to disable particular options of a select custom field with the groovy script runner. I´ve already tried to find a solution with optionManager.disableOption but obviously my groovy skills aren´t good enough. 

 

Can somebody give me a code example to disable a particular option of a custom field?

 

Thank you in advance for your support.

 

Best regards

Dennis

1 answer

1 accepted

2 votes
Answer accepted
Mark Markov
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.
August 20, 2018

Hello @Dennis S_

Here is example that get options for the field checks values of options and disable option with given value

import com.atlassian.jira.component.ComponentAccessor

def issue = ComponentAccessor.getIssueManager().getIssueObject("TEST-1") // get issue where field exist
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Your CustomField Name")
def optionsManager = ComponentAccessor.getOptionsManager()
def options = optionsManager.getOptions(customField.getRelevantConfig(issue))
options.each {
if (it.value == "some option value"){
optionsManager.disableOption( it)
}

}
Dennis S_
Contributor
August 21, 2018

That´s exactly what I was looking for. Thanks a lot for your support!

Srikanth Ganipisetty
Contributor
March 3, 2022

@Mark Markov  Thanks it worked, where the other script I tried on community has disabled all options by skipping the "issue key" I given.  Yours has fixed it. 

But how can I do bulk update for a list of 100 options in a 6000 entry MLCS/Single-select field? 

Please share your ideas. 

Thanks,

Srikanth Ganipisetty

Scott Boisvert
Contributor
March 25, 2022

This doesn't appear to workin in Behaviours, unless I'm missing something.

Like Srikanth Ganipisetty likes this
Srikanth Ganipisetty
Contributor
April 4, 2022

Call it in Script Console/Post Functions using Workflow changes/Trigger it using automation rules in "Automation for Jira".

 

Not the behavior - Here you can hide them, but cannot perform actions like "Disabled/Deleted/Enabled"

Thanks,

Srikanth Ganipisetty

Suggest an answer

Log in or Sign up to answer