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

Sachin Dhamale November 10, 2013
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

0 votes
Answer accepted
Bharadwaj Jannu
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.
November 12, 2013

just try with

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

Sachin Dhamale November 12, 2013

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


Bharadwaj Jannu
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.
November 12, 2013

ok Sachin, is it throwing any error?

Bharadwaj Jannu
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.
November 12, 2013
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.

Bharadwaj Jannu
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.
November 12, 2013
0 votes
MJ
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 11, 2013

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.

Sachin Dhamale November 12, 2013

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