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

Accepted Answer
0 votes

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 votes

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
Community showcase
Posted Sep 18, 2018 in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

24,978 views 2 7
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