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.
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")
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.