JQL query: field "starts with..."

DIGIT CITnet March 5, 2013

Hello,

I would like to create a filter to show those issues whose custom field "Name" starts by a specific letter, let's say, "A".

I am currently using:

Name ~ "A*"

But it is returning wrong results (issues where Name does not start with "A")

Does anybody have any clue about how to perform that search?

Thanks a lot,

Marc

6 answers

1 accepted

1 vote
Answer accepted
JamieA
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.
March 5, 2013

You should be able to use issueFieldExactMatch from the same plugin...

issueFunction in issueFieldMatch("", "Name", "A.*")

DIGIT CITnet March 7, 2013

Hello Jamie,

Thanks for your answer.

However, I am receiving an error:

The JIRA server could not be contacted. This may be a temporary glitch or the server may be down.

When performing the following query:

issueFunction in issueFieldMatch("project=XXX", "Nom", "^[a-eA-E]")

If I change and use the field "Assignee" instead of the custom field "Nom" (Text Field (< 255 characters)), it works fine.

Do you know what may be happening?

Regards,

Marc

DIGIT CITnet March 7, 2013

Logs, in case they may help:

2013-03-08 08:21:48,804 http-8080-2 DEBUG bignoan 501x5364x2 nda8qa 158.166.147.59,158.167.133.6,127.0.0.1 /rest/issueNav/1/issueTable/ [jira.groovy.jql.AbstractScriptedJqlFunction] Subquery (project=PMOCONTACT) took 30 ms
2013-03-08 08:21:48,823 http-8080-2 ERROR bignoan 501x5364x2 nda8qa 158.166.147.59,158.167.133.6,127.0.0.1 /rest/issueNav/1/issueTable/ [common.error.jersey.ThrowableExceptionMapper] Uncaught exception thrown by REST service
java.lang.NullPointerException
	at java.util.regex.Matcher.getTextLength(Matcher.java:1140)
	at java.util.regex.Matcher.reset(Matcher.java:291)
	at java.util.regex.Matcher.&lt;init&gt;(Matcher.java:211)
	at java.util.regex.Pattern.matcher(Pattern.java:888)
	at sun.reflect.GeneratedMethodAccessor1519.invoke(Unknown Source)  &lt;+1&gt; (DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSite.invoke(PojoMetaMethodSite.java:189)
	at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
	at com.onresolve.jira.groovy.jql.EntityMatch$_getQuery_closure1.doCall(script1362578899598384340786.groovy:107)  &lt;+2&gt; (DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
	at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:877)
	at groovy.lang.Closure.call(Closure.java:412)
	at org.codehaus.groovy.runtime.DefaultGroovyMethods.eachWithIndex(DefaultGroovyMethods.java:1368)
	at org.codehaus.groovy.runtime.dgm$206.invoke(Unknown Source)

There are more lines, but characters are limited here.

Thanks!

JamieA
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.
March 7, 2013

Oh... it's a bug in my code. Can you modify the input query to be "project = XXX and Nom is not empty". Check that query works on its own before feeding to the function.

(https://jamieechlin.atlassian.net/browse/GRV-207)

DIGIT CITnet March 7, 2013

Thanks Jamie! Here the results of the tests:

project= XXX AND Nom is not EMPTY

Returns apropriate issues.

issueFunction in issueFieldMatch("project= XXX AND Nom is not EMPTY", "Nom", "^[a-eA-E]")

Does not return any issue (it should). No errors are logged.

JamieA
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.
March 7, 2013

"^[a-eA-E].*"

worked for me... although I think yours should have worked too.

Like # people like this
DIGIT CITnet March 7, 2013

Great Jamie. It works with this regex!

Thanks again!

Marc

Ondrej Matejka May 19, 2014

Hi Jamie,

I have a similar issue, looking for issues with lables starting with "c/" (as in c/something). Unfortunately, the qurey I am using also returns results like "asc/something" etc, i.e. not starting with but containing "c/".

My query: issueFunction in issueFieldMatch("", labels, "c/.*")

Could you please advise?

Thanks,

Ondrej

2 votes
Lorenzo Giulioni June 24, 2019

Not sure if you solved yet, but you have to use % instead of *
eg: summary ~ "Frontend:%"

0 votes
Phillip Ponzer [Cprime]
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.
March 31, 2017

If you got to this question and are wanting to match against a project's name, this works for me:

project IN projectMatch("project name prefix.+")
0 votes
JamieA
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.
May 19, 2014

Should be: "^c.*"

0 votes
MB
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.
August 12, 2013

You could also use:

Name LIKE 'A%'

0 votes
Henning Tietgens
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.
March 5, 2013

This is not possible without writing you own jql function as a plugin (or using Script Runner to script this jql).

DIGIT CITnet March 5, 2013

Thanks for you answer, Henning.

However, I have one doubt: I have not been able to find where to define a new JQL function within Script Runner.

Even if I follow Jamie Echlin's instructions, I cannot find the described options: Admin -> Script JQL Functions

Quick Start

  • Go to Admin -> Script JQL Functions.
  • Click Add New Function

https://jamieechlin.atlassian.net/wiki/display/GRV/Scripted+JQL+Functions#ScriptedJQLFunctions-Writingyourownfunctions

Any clue would be appreciated! Thanks

Henning Tietgens
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.
March 5, 2013

Yes, scripted JQL is currently only in the beta version.

Henning Tietgens
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.
March 5, 2013

For me it's the last point of the Plugins menu and a link on the main admin page in the plugin section under Other.

Henning Tietgens
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.
March 5, 2013

Do you use the current BETA version?

DIGIT CITnet March 5, 2013

No, I am currently using 2.0.7. Should I update to 2.1-BETA-8? to use these options?

DIGIT CITnet March 5, 2013

Thanks Henning, it works!

Suggest an answer

Log in or Sign up to answer