Hi,
I'm new to both Java and JIRA-Development so please forgive the potentially ignorant question. :)
I'm trying to write a plugin that provides a custom select field, which is automatically populated with data from another service. So far, I've got my field and I'm setting the available options in getVelocityParameters(...) like so:
Options options = this.optionsManager.getOptions(fieldConfig);
if (options.isEmpty()) {
ArrayList<JSONObject> projects = GetProjectList();
for (int i = 0; i < projects.size(); i++) {
Long id = projects.get(i).getLong("id");
String identifier = projects.get(i).getString("name");
this.optionsManager.createOption(fieldConfig, null, id, identifier);
}
}
options = this.optionsManager.getOptions(fieldConfig);
This works, but all options have to be deleted before the field is updated.
Instead of the if-clause, I tried to just clear all options by calling
this.optionsManager.removeCustomFieldOptions(field)
and then repopulate the field every time. That also worked in that the field's options would always get updated, but the selection wouldn't save anymore.
I'm wondering
- Is there a better way to do this?
- Is it possible to render my field with autocomplete, like, for example the priority field?
Any help is much appreciated.
Edit:
Spent some more time on this. Apparently, the real issue with clearing the options before each update is that the newly added ones also get new id's - which don't match those stored in the db. It doesn't seem like I can just set the id's myself, though.