Forums

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

Unable to add data to my custom field options

Anita Y September 14, 2018

Hi , 

 

I have a list of 3000 records and trying to add to a custom field but the values are not populating .Custom field is a label.

 

def populateCustomField(List carIDAppList){
def projectMgr = ComponentAccessor.getProjectManager() as CachingProjectManager;
IssueContextImpl issueContext = getIssueContext() as IssueContextImpl;
//IssueContextImpl issueContext = IssueContextImpl.getIssueContext() as IssueContextImpl;
def customeFieldMgr = ComponentAccessor.getCustomFieldManager() as CachingCustomFieldManager
def customeField = customeFieldMgr.getCustomFieldObject(customFieldId);
FieldConfig fieldConfig = customeField.getRelevantConfig(issueContext);
def optManager = ComponentAccessor.getOptionsManager() as DefaultOptionsManager;
OptionsImpl optionsImpl = optManager.getOptions(fieldConfig) as OptionsImpl;

List<Option> lists = new ArrayList();
Long opId = 1L;
carIDAppList.each {
if (optionsImpl.getOptionForValue(it.toString(), null) == null) {
Option option = optManager.createOption(fieldConfig, null, opId, it.toString());
opId += 1L;
lists.add(option);
}

}
if (lists.size() > 0) {
optManager.updateOptions(lists);
}
}

 

1 answer

0 votes
Nic Brough -Adaptavist-
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.
September 15, 2018

There's two problems here:

  1. Label fields do not take "options", they take "label" objects.  
  2. Label fields do not have a list of options, you have to add new labels to issues.

See https://docs.atlassian.com/software/jira/docs/api/7.12.1/index.html?com/atlassian/jira/issue/label/LabelManager.html probably

Anita Y September 15, 2018

sorry it's not a label , it's a select list (multiple choices) and converted to a search bar .

When i tried with 30 records it was loaded .Initially it was a  stand alone groovy script and then converted to a groovy class not sure if that's the issue.

class CarIDAppData extends FieldBehaviours {

 static void main(String[] args) {
CarIDAppData st = new CarIDAppData();
carIDAppList =st.processCarIDdata()
st.populateCustomField(carIDAppList);

}





}

Suggest an answer

Log in or Sign up to answer