Forums

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

script of add values to single select list custom field

ozd
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 21, 2018

Hello i am trying add values to a single select custom field select list.

i want to add the values by groovy script. (not a post function, and not related to any issue)

script of add values to single select list custom field - ScriptRunner for JIRA - Service Desk

  • import com.atlassian.jira.component.ComponentAccessor
    import com.atlassian.jira.issue.fields.CustomField

    // Get access to the Custom Field Manager
    def customFieldManager = ComponentAccessor.getCustomFieldManager();

    // Replicate the lines from here down to the return statement for each field to be updated

    // Get my Custom field by its ID
    CustomField cf= customFieldManager.getCustomFieldObject("customfield_10802")
    // Update my Custom Field using the paramaters of (Long ID, String Name, String Description, Custom Field Searcher)
    customFieldManager.updateCustomField(cf.getIdAsLong(),"Demo Text Field", "A Demo Text Field", customFieldManager.getCustomFieldSearcher("com.atlassian.jira.plugin.system.customfieldtypes:textsearcher"))

    but its updating the name of the custom field , not the select list values .

    i also tried to build using the java api ,
    and use the create option from here :
    https://docs.atlassian.com/software/jira/docs/api/7.9.0/com/atlassian/jira/issue/customfields/option/Options.html#addOption-com.atlassian.jira.issue.customfields.option.Option-java.lang.String-
    no success.

    all the examples found and generally use is to update the value inside the issue , but this is not what i want.

2 answers

1 vote
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 21, 2018

Hello @ozd

You can create option via Script console like this

import com.atlassian.jira.component.ComponentAccessor

//we need Issue object where field present to get FiendConfig of customfield
def issue = ComponentAccessor.getIssueManager().getIssueObject("TEST-1")
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObjectsByName("ListA").first()
def config = customField.getRelevantConfig(issue)
optionsManager.createOption(config, null, null, "option value")
0 votes
Oz_Dagmi August 23, 2018

Thanks @Mark Markov for youre answer.

its possible to to update the values whiteout using the issue instance ?

I tried some code i found at the internet like this one : 


import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField

// Get access to the Custom Field Manager
def customFieldManager = ComponentAccessor.getCustomFieldManager();

// Replicate the lines from here down to the return statement for each field to be updated

// Get my Custom field by its ID
CustomField cf= customFieldManager.getCustomFieldObject("customfield_10802") 
// Update my Custom Field using the paramaters of (Long ID, String Name, String Description, Custom Field Searcher)
customFieldManager.updateCustomField(cf.getIdAsLong(),"Demo Text Field", "A Demo Text Field", customFieldManager.getCustomFieldSearcher("com.atlassian.jira.plugin.system.customfieldtypes:textsearcher"))

but its updating the name of the custom field , not the select list values .

 

Thanks

Oz

Suggest an answer

Log in or Sign up to answer