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.ComponentAccessor
import com.atlassian.jira.issue.fields.config.FieldConfig
import com.atlassian.jira.issue.context.IssueContextImpl
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.customfields.option.OptionsImpl
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.json.JsonSlurper
import groovy.transform.BaseScript
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
import org.apache.log4j.Logger
import org.apache.log4j.Level
def log = Logger.getLogger("com.acme.CreateSubtask")
log.setLevel(Level.DEBUG)
@BaseScript CustomEndpointDelegate delegate
sortOptions(
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 options
return Response.ok(new JsonBuilder(field).toString()).build()
}
Any help would be appreciated.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.