I've implemented the BulkImportCustomFieldValues example using PHP and cURL, however, the values get added at the end of the existing option list, rather than in their respective alphabetical positions in the list. I haven't found any documentation on how to programmatically sort the option list after using my BulkImportCustomFieldValues script. What would you suggest?
I figured I could create a custom REST endpoint to a script that sorts the specified field's options. However, I'm stuck trying to figure out how to get the FieldConfig object so that I can get the field options and sort them. Here's what I have so far.
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.fields.config.FieldConfigimport com.atlassian.jira.issue.context.IssueContextImplimport com.atlassian.jira.issue.customfields.option.Optionimport com.atlassian.jira.issue.customfields.option.OptionsImplimport com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegateimport groovy.json.JsonBuilderimport groovy.json.JsonSlurperimport groovy.transform.BaseScriptimport javax.ws.rs.core.MultivaluedMapimport javax.ws.rs.core.Responseimport org.apache.log4j.Loggerimport org.apache.log4j.Leveldef log = Logger.getLogger("com.acme.CreateSubtask")log.setLevel(Level.DEBUG)@BaseScript CustomEndpointDelegate delegatesortOptions( httpMethod: "POST", groups: ["jira-administrators"]) { MultivaluedMap queryParams, String body -> def optionsManager = ComponentAccessor.getOptionsManager() def customFieldManager = ComponentAccessor.getCustomFieldManager() log.debug("request body: " + body) def jsonSlurper = new JsonSlurper() def object = jsonSlurper.parseText(body) log.debug("request object: " + object) def field = customFieldManager.getCustomFieldObject((Long)object.field.toInteger()) log.debug("field: " + field) field.getOptions(null, ...) //use OptionsImpl sort function to sort the optionsreturn Response.ok(new JsonBuilder(field).toString()).build()}
Any help would be appreciated.
It looks like you're new here. Sign in or register to get started.