Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,360,043
Community Members
 
Community Events
168
Community Groups

Sort BulkImportCustomFieldValues

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?

1 answer

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.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Online AMA this week: Your project management questions answered by Jira Design Lead James Rotanson

We know that great teams require amazing project management chops. It's no surprise that great teams who use Jira have strong project managers, effective workflows, and secrets that bring planning ...

181 views 1 6
Read article

Atlassian Community Events