What is a jql for getting issue order by accending order of value of custom field

List<Issue> getIssuesFromProject(Long projectId) throws SearchException {
		JqlQueryBuilder builder = JqlQueryBuilder.newBuilder();
		builder.where().project(projectId);
		builder.orderBy().addSortForFieldName("STRINGVALUE", SortOrder.ASC, true);
		
		Query query = builder.buildQuery();
		SearchResults results = ComponentManager.getInstance().getSearchProvider().search(query,ComponentAccessor.getJiraAuthenticationContext().getUser(), PagerFilter.getUnlimitedFilter());
		return results.getIssues();
	}

In above codei want to get issue for given project ID and order by customfield value in asccending order.

"STRINGVALUE" is the column name of customfieldvalue table of jira where value of customfield store

but its not working can anyone tell me what is wrong in it or is any other way to get issue orderby of value of customfield

2 answers

1 accepted

just try with

builder.orderBy().add("your customfield name",SortOrder.ASC);

Hi Bharadwaj

i try this but its not working

	List<Issue> getIssuesFromProject(Long projectId) throws SearchException {
		final CustomField customField1 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("WBS");
		JqlQueryBuilder builder = JqlQueryBuilder.newBuilder();
		builder.where().project(projectId);
		//builder.orderBy().issueKey(SortOrder.ASC);
		builder.orderBy().add("WBS" , SortOrder.ASC ,true);
		//builder.orderBy().addSortForFieldName("STRINGVALUE", SortOrder.ASC );
		//builder.orderBy()("STRINGVALUE", SortOrder.ASC,true);
		Query query = builder.buildQuery();
		SearchResults results = ComponentManager.getInstance().getSearchProvider().search(query,ComponentAccessor.getJiraAuthenticationContext().getUser(), PagerFilter.getUnlimitedFilter());
		return results.getIssues();
	}

in this WBS is my customfield name

WBS field Contain

1

2

3


ok Sachin, is it throwing any error?

List&lt;Issue&gt; getIssuesFromProject(Long projectId) throws SearchException {
	    
	    JqlQueryBuilder builder = JqlQueryBuilder.newBuilder();
	    builder.where().project(projectId);
	    
	    builder.orderBy().add("FIN" , SortOrder.ASC ,true);
	    
	    
	    Query query = builder.buildQuery();
	    SearchResults results = searchService.search(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(),query, PagerFilter.getUnlimitedFilter());
	    return results.getIssues();
	}
in my constructor I wrote like this to get searchService
import com.atlassian.jira.bc.issue.search.SearchService;
public EditLink(SearchService searchService){
		this.searchService=searchService;
}

this worked for me and FIN is of select list type.

0 vote

In JQL you would not order by the name of the custom field, rather by the custom fieldID. This would look something like "ORDER BY cf[10100] ASC" where the value of cf[] determines which custom field is being used.

but Mick how we use this custom field ID in this syntax.

builder.orderBy().addSortForFieldName("STRINGVALUE", SortOrder.ASC, true);

Means where we mention customfield ID in orderBy() method

Can you modify above code with corrected code according to requirement

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,338 views 14 20
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot