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

This widget could not be displayed.

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.

This widget could not be displayed.

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 Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted yesterday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

55 views 1 0
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