How to perform case INsensitive search using issueFieldExactMatch() function

SWAPNIL SRIVASTAV December 5, 2019

Hello All,

I want to search issues whose summary EXACTLY match with given string but it should be case-insensitive. I used below jql

issueFunction in issueFieldExactMatch("project = ABC", "Summary", "(?i)Test") 

I know there is an issue with summary "test", but the JQL does not return it as a result.

Script Runner version 5.5.9

Jira version: 7.13.5

Using JIRA through server

Could you please help

Thanks and Regards,

Swapnil Srivastav

1 answer

1 accepted

0 votes
Answer accepted
Ilya Turov
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.
December 5, 2019

I don't know why it doesn't work, but looking at documentation, you can apply the workaround and search like this:

issueFunction in issueFieldMatch("project = ABC", "Summary", "^(?i)Test$") 

SWAPNIL SRIVASTAV December 5, 2019

Hello @Ilya Turov ,

Thanks for your quick response.

It is working on JQL advance search tab but not when I am using the same in groovy script along with JQL Query Parser

Could you please help me with that.

Thanks and Regards,

Swapnil Srivastav

Ilya Turov
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.
December 5, 2019

the thing is, I didn't even get it to work in advance search tab

can you show the code you are using? maybe, I'll be able to help then

also you can try same workaround in script, maybe the behaviour is different

SWAPNIL SRIVASTAV December 5, 2019

Hello @Ilya Turov ,

Regret to inform, but the above JQL is not working for me as I need to perform EXACT search. I am using below query:

issueFunction in issueFieldExactMatch("project = ABC and issuetype=DE", "summary", "FGH")

and it is returning correctly the issues with summary "FGH", but I want to list issues with summary "fgh" also.

I cannot use issueFieldMatch() because that would give results with nearby values as well like "fghij" or "ABCFGH".

I need to perform exact search but it should be case-INsensitive.

Kindly help

Regards,
Swapnil Srivastav

Ilya Turov
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.
December 5, 2019

searching for '^test$' with regular fieldMatch will work same as searching for 'test' with exactFieldMatch since ^ and $ stand for beginning and end of the string, hence 'workaround'

SWAPNIL SRIVASTAV December 5, 2019

Hello @Ilya Turov ,

Yes, I know, it should as per documentation , but it is not. I have a summary as "Other" but on using,

issueFunction in issueFieldExactMatch("project= ABC and issuetype =DE", "Summary", "^Other$")

no issues are given as result. I think it is not accepting any sort of regular expression

Regards,

Swapnil

Ilya Turov
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.
December 5, 2019

because you are still trying to use issueFieldExactMatch, while I'm telling you to try issueFieldMatch

SWAPNIL SRIVASTAV December 6, 2019

Hi @Ilya Turov ,

Sincere apologies.

I got confused between the two. Now, it works properly in JQL query but not when I use in groovy. As groovy treats ${} as interpolation and it is expecting a literal value after $ sign or an escape character but if put an escape character, compilation error is resolved but the JQL wont be correct then.

Below is the groovy, I am trying:

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.searchSearchProvider

import com.atlassian.jira.jql.parser.JqlQueryParser

import com.atlassian.jira.web.bean.PagerFilter

import com.atlassian.jira.issue.Issue

 

def summaryObj = getFieldById(getFieldChanged())

def summary = summaryObj.getValue()

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)

def searchProvider = ComponentAccessor.getComponent(SearchProvider)

def issue = underlyingIssue

if(issue == null)

{

     return

}

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def query = jqlQueryParser.parseQuery("issueFunction in issueFieldMatch('project = Cluster and key!= "+issue.key+"', 'Summary', '^(?i)"+summary+"$')")

if(results.getTotal()>0)

{

     summaryObj.setError("Issue Summary already exists.")

}

else

{

     summaryObj.clearError()

}

Regards,

Swapnil Srivastav

Ilya Turov
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.
December 6, 2019

escape character is not going to mess with your query, because it's well, escape character. \$ is going to be evaluated as $ in your query

so using this:

"issueFunction in issueFieldMatch('project = Cluster and key!= ${issue.key}', 'Summary', '^(?i)${summary}\$')"

should perfectly work

SWAPNIL SRIVASTAV December 6, 2019

Hello @Ilya Turov ,

Thanks a lot for being continuous and replying with new solutions.

I tried the exact same line, but it is not working as expected. It does not give compilation error but allows duplicate summaries if the case of text  is different.

Best Regards,

Swapnil Srivastav

SWAPNIL SRIVASTAV December 9, 2019

Hi @Ilya Turov ,

The solution you suggested works perfectly.

JQL:

issueFunction in issueFieldMatch("project = ABC and issuetype = "DE", "Summary", "^(?i)Test$")

and for groovy:

issueFunction in issueFieldMatch("project = ABC" and key != ${issue.key}", "Summary", "^(?i)${summary}\$")

Thanks a lot for the response and apologies for creating confusions.

Thanks and Regards,

Swapnil Srivastav.

Ilya Turov
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.
December 9, 2019

as long as you got it to work :)

Suggest an answer

Log in or Sign up to answer