Forums

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

How to delete option value from custom field

Manu Mishra
Contributor
August 3, 2018

Hi,


I have a custom field (Single_Select) in my jira instance. The field has some option values in it, most the values has been disabled. As we are in process of cleaning up our instance, so we want to delete the disabled values from custom field option. Let me know if there is any way i can delete those values from "Script Runner" and how? Because there are approx. >100 option values.

2 answers

3 votes
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 3, 2018

Hello @Manu Mishra

Try this, replace issue key with actual issue key and test it in staging environment first

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.getDisabled()){
optionsManager.deleteOptionAndChildren(it)
}
}
Manu Mishra
Contributor
August 3, 2018 edited

@Mark Markov

@Mark Markov 

I believe the script will delete the "custom field" from the issue where the the field exist. However my question is different, i want to delete the options value from the custom field, i have enclosed the screen shot for your reference. 
Basically when we go to Admin>Issues>Custom Fields>Configure>Edit Options . So there are many custom field options, so what i want is to delete those option values which are disabled. In the screen shot there are 5 CF values, out of which we need to delete only (#2, #4)

Manu Mishra
Contributor
August 3, 2018

Capture.PNG

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 3, 2018

And script above will delete this options from configuration.

It looks strange, because optionsManager need some context. It is architecture feature. 

I ve tested it on my environment and it works. 

Manu Mishra
Contributor
August 3, 2018

@Mark Markov
So what's the issue key i have to pass? there are so many issues where this value exist and we only want to delete (cd & gh)? 

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 3, 2018

Any issue key, where field exists on the screen.

Manu Mishra
Contributor
August 3, 2018

@Mark Markov

So according to you, when we pass any issue key in variable, so option under that field will be deleted from field config? What i concerned about, this should not delete the custom field.  

Manu Mishra
Contributor
August 3, 2018 edited

@Mark Markovscripconsole.PNG

i ran this script from script console (script runner), however it not doing anything. Means, neither it deleted the option from issues nor under custom field config. Rather printing the output like above: 

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 4, 2018

This output is normal.

Are you sure that it not deleted from config?

I ve checked it again and it

Снимок экрана 2018-08-04 в 10.50.37.png Снимок экрана 2018-08-04 в 10.50.54.png Снимок экрана 2018-08-04 в 10.51.10.png

Raynard Rhodes
Contributor
May 14, 2020

@Mark Markov it worked like a charm...I changed .deleteOptions with .disableOptions. Thank you.

1 vote
Alexey Matveev
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 4, 2018

Hello,

You can use the Power Scripts add-on to delete such options. Here is the link to the Power Scripts add-on:

https://marketplace.atlassian.com/apps/43318/power-scripts-jira-script-automation?hosting=cloud&tab=overview

For example, to delete the "Option" from the global context of custom field "Select List" would be like this:

admDeleteCustomFieldOption("Option", "Select List");

You can find more info on admDeleteCustomFieldOption here:

https://confluence.cprime.io/display/SIL/admDeleteCustomFieldOption

Suggest an answer

Log in or Sign up to answer