JAVA API - get all contexts of customfield

Nir Haimov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 6, 2020

Hi,

We have few single select & multi select customfield with many contexts.

Each context for different projects, with different values to choose in the select drop down.

 

Can someone help me to find how can i get list of all contexts of a customfield?

And after getting the list, how to check for what are the options in each context?

 

Thanks,

Nir

3 answers

1 accepted

1 vote
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 6, 2020

You can use FieldConfigSchemeManager and getConfigSchemeForField to get all the contexts

Then OptionsManager and getOptions to get the options in each of the Configs.

For example, in groovy:

def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName('Severity')
ComponentAccessor.fieldConfigSchemeManager.getConfigSchemesForField(cf).each{
log.info ComponentAccessor.optionsManager.getOptions(it.oneAndOnlyConfig).collect{it.value}
}
Nir Haimov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 9, 2020

Thank you @Peter-Dave Sheehan !

That's exactly what i needed :) 

Lokesh D February 11, 2021

We are requiring all the context names, relevant project name, issuetypes instead of options.

Is there any change to above script would be required ?

Also, if we need to get similar info for more than 1 field, wondering if it needs to be added next to Severity in above example ?

0 votes
Matt Doar
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 6, 2020

For the Java API I would start at a page such as 

/secure/admin/ConfigureCustomField!default.jspa?customFieldId=14083

and check in actions.xml source file for the class that is behind that URL. Then in that class and the related jsp file, look for the Manager object that they iterate over to find each context

That lead me to the class ConfigureCustomField.java and the method getConfigs, which has schemeManager.getConfigSchemesForField(customField);

0 votes
Thomas Magny-Garcia
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.
February 6, 2020

Hi @Nir Haimov 
On my side, I am able to get every allowed values using API.
For instance, by reaching this URL : https://xxx/jra/rest/api/latest/issue/createmeta?projectKeys=MyProject&issuetypeNames=Test&expand=projects.issuetypes.fields
I get this response :Capture.PNG
You may see the highlighted lines: there are the allowed values for the customfield_11110.

Hope it helps !

Suggest an answer

Log in or Sign up to answer