Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,299,851
Community Members
 
Community Events
165
Community Groups

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

Edited

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

0 votes

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")

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

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

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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence

An update on Confluence Cloud customer feedback – June 2022

Hi everyone, We’re always looking at how to improve Confluence and customer feedback plays an important role in making sure we're investing in the areas that will bring the most value to the most c...

324 views 2 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you