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 Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Monday in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

685 views 6 13
Read article

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