Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Why doesn't my script field search properly through JQL?

Dawid Skowron November 16, 2021

Hi,

When i am trying to search by my scripted field (code below) for example:
"product done by it" ~ no - gives me back all issues (with yes, no, No IT tasks)
"product done by it" ~ yes - gives nothing even though i have some issues with "yes"
Of course i reindexed after change

1.jpg

Am i doing something wrong? 

import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchResults
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.web.bean.PagerFilter
def searchForIssues(ApplicationUser searchUser, String initialJQL) {
def searchService = ComponentAccessor.getOSGiComponentInstanceOfType(SearchService)
def queryParser = ComponentAccessor.getOSGiComponentInstanceOfType(JqlQueryParser)
def query = queryParser.parseQuery(initialJQL)
SearchResults search = searchService.search(searchUser, query, PagerFilter.getUnlimitedFilter())
return search.results
}
def scriptResult = "Don't know"
enableCache = {-> false}
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def jql = "key in issueMatrix('${issue.key}', 'Tasks in IT Domains')"
def issues = searchForIssues(user, jql)

if (issues){
def result = issues.every{
log.error(it.status.name)
it.status.name == 'Done' || it.status.name == 'Canceled'

}

log.error(result)
if (result){
scriptResult = "Yes"

} else {
scriptResult = "No"
}

}
else{
scriptResult = "No IT tasks"
}
return scriptResult

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
PD Sheehan
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 22, 2021

Your script should output one of 4 values:

  1. Yes
  2. No
  3. No IT Tasks
  4. Don't Know

If you doa JQL with 

"product done by it" ~ no 

I'd expect all issues where you'd expect 2, 3 or 4 to be returned.

I'd look at the actual value returned for issues you know should return a "Yes" and make sure the script works as designed. I'm especially uncertain about the "in issueMatrix" function in this context.

But something else to consider, since you only have 4 discrete values in your script, there is no reason not to use the "Exact Text Searcher" then you will be able be more specific with your JQL

For example:

"product done by it" = Yes
"product done by it" = No
"product done by it" in (No, "No IT Tasks")
Dawid Skowron November 24, 2021

I also tried the "Exact Text Searcher" but unfortunately the problem must lie somewhere else because the values shown when searching in JQL are different from those in the issue itself

PD Sheehan
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 24, 2021

It might be caused by enabledCache={->false}

In the documentation (https://docs.adaptavist.com/sr4js/latest/features/script-fields) there is this warning:

If your script relies on data from external system you can invalidate the cache altogether, although you should test first, particularly if you are doing things like running complex JQL queries. 

I wonder if this is a case when disabling the cache is hurting you more than helping you.

I would try this:

  1. remove the enableCache line
  2. performa complete re-index
  3. try your jql search again
Dawid Skowron November 25, 2021

Unfortunately, nothing has changed. When searching only the first task is found correctly the rest of the searched tasks are all tasks that have any values in "product done by it".

TAGS
AUG Leaders

Atlassian Community Events