Forums

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

I want to add a value to select list field

aditya442 August 9, 2024

Hi,

I have a target release field and would want to add value to it based on an issue creation. This field is not being used in the current issue that is being created but in another project. Any pointers?

example - 

Project A with Issue Type Release. On creation of Release in Project A, the summary should get added to the Target Release (Project Specific Select List) so it can be used in Project B with Issue Type Target Release.

Any pointers would be appreciated?

Thanks,

1 answer

1 accepted

1 vote
Answer accepted
Florian Bonniec
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 9, 2024

Hi @aditya442 

 

String optionName = XXXX
CustomField customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject('customfield_xxxxxx')
Project project = ComponentAccessor.getProjectManager().getProjectByCurrentKey('XXXX')
OptionsManager optionManager = ComponentAccessor.getOptionsManager()
FieldConfigScheme fieldContexts = getFieldContext(customField, project)
FieldConfig fieldContxt = fieldContexts.getConfigs().get(fieldContexts.getConfigs().keySet().first())
if(fieldContxt){
    if(!optionManager.getOptions(fieldContxt).getOptionForValue(optionName, null)){
            optionManager.createOption(fieldContxt, null, null, optionName)
        }
    }

I did not test the script but the section that add the option is the one I use in my scripts

Regards

aditya442 August 11, 2024

Thanks Florian for the response.I tried with the code you shared and it gives me an error. Please suggest.

 

Screenshot 2024-08-12 at 10.37.45 AM.png

Thanks,

Aditya

Florian Bonniec
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 13, 2024

What is the error message  ?

aditya442 August 13, 2024

This is the error I am receiving

Screenshot 2024-08-13 at 5.49.19 PM.png

This is my piece of code.

Screenshot 2024-08-13 at 5.50.50 PM.png

Thanks,

Aditya

aditya442 August 22, 2024

@Florian Bonniec any suggestion?

Florian Bonniec
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 22, 2024

Hi

 

I just tested the script and fixed the issue

import com.atlassian.jira.issue.fields.config.FieldConfig
import com.atlassian.jira.issue.fields.config.FieldConfigScheme
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.project.Project
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.component.ComponentAccessor




String optionName = "XXXXX"
CustomField customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject('customfield_XXXXX')
Project project = ComponentAccessor.getProjectManager().getProjectByCurrentKey('XXX')
OptionsManager optionManager = ComponentAccessor.getOptionsManager()
FieldConfigScheme fieldContexts = ComponentAccessor.getFieldConfigSchemeManager().getRelevantConfigScheme(project, customField)
if(fieldContexts){
    FieldConfig fieldContxt = fieldContexts.getConfigs().get(fieldContexts.getConfigs().keySet().first())
    if(fieldContxt){
        if(!optionManager.getOptions(fieldContxt).getOptionForValue(optionName, null)){
            optionManager.createOption(fieldContxt, null, null, optionName)
        }
    }
}

Regards

aditya442 August 22, 2024

Thanks a lot @Florian Bonniec . It worked.

Suggest an answer

Log in or Sign up to answer