Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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

Suggest an answer

Log in or Sign up to answer
0 votes
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 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")

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

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 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

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