JQL and concatenation

Hi,

Does anyone know if or how it is possible to use concatenations in JQL?

example: text ~ "Fixed Text".currentUser()."Fixed Text"

I have not been able to find any reference to concatenations in any documentation anywhere and have not seen any similar questions. So it seems like it is simply not possible. Would of course be great if I am wrong about this.

Thanks.

2 answers

Hi :)

The usual way to build your JQL query is to use JqlClauseBuilder like this:

JqlQueryBuilder builder = JqlQueryBuilder.newBuilder();
JqlClauseBuilder jqlClauseBuilder = builder.where().project("TP").and().reporterUser("admin").or().reporterUser("test");

//now perform the actual search (only interested in number of results)
searchService.searchCount(user, builder.buildQuery());
//or if you need the standard result set
searchService.search(user, builder.buildQuery(), PagerFilter.getUnlimitedFilter());

More info in this article.

That way you can build most of your queries. Sometimes, when you need to add a custom query string, to create a more advanced query, you need to "concatenate" the additional string (in a WHERE clause) to your already created jql, which can be accomplished like this

JqlQueryBuilder builder = JqlQueryBuilder.newBuilder();
JqlClauseBuilder jqlClauseBuilder = builder.where().project("TP").and().reporterUser("admin").or().reporterUser("test");

String finalQueryString = builder.buildQuery().getWhereClause().toString();
finalQueryString += " AND ( project = TP )"; // this is where you concatenate your custom jql string

SearchService searchService = ComponentAccessor.getComponent(SearchService.class);
if (searchService != null)
	try {
		finalQueryString = finalQueryString.replace("{", "(").replace("}", ")"); // replace special chars...
		SearchService.ParseResult parseResult =  searchService.parseQuery(user, finalQueryString);
		if (parseResult.isValid()) {
			searchService.searchCount(user, parseResult.getQuery());
			...
		} else {
			// jql is not valid
		}
	} catch (SearchException e) {
		// an error occurred while performing the search
	}
}

I hope it helps.

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 ...

2,798 views 11 18
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