Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,555,951
Community Members
 
Community Events
184
Community Groups

Sort BulkImportCustomFieldValues

Artemy Matvienko
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.
Dec 15, 2017

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

0 votes
Artemy Matvienko
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.
Dec 18, 2017 • edited

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
AUG Leaders

Atlassian Community Events