The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

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

Scriptrunner Jira, getting 0 records with searchService.search

Mehhss
May 9, 2024
def masterFilter = "'ISSUETYPE' IN ('PERSON') AND 'STATUS' IN ('ACTIVE, INACTIVE') AND " +
            "PROJECT IN ('Project1') AND 'ID NUMBER' ~ 'ID1234' ORDER BY 'END DATE'  DESC, 'START DATE' DESC";
def parseResults = jqlQueryParser.parseQuery(masterFilter);                      
def masterResults = sServ.search(executeUser, parseResults, PagerFilter.getUnlimitedFilter())
 ;  

log.warn masterResults.total // gives me 0 records 

but when I search with the Query it returns 3 records for ID1234

Is there any mistake in my code for searching the results ?

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
May 10, 2024

Hi @Mehhss

For your requirement, I suggest taking a look and ScriptRunner's HAPI feature to simplify your code.

You could try something like below on the ScriptRunner Console to get the total number of issues returned in the result

Issues.count("""'ISSUETYPE' IN ('PERSON') AND 'STATUS' IN ('ACTIVE, INACTIVE') AND PROJECT IN ('Project1') AND 'ID NUMBER' ~ 'ID1234' ORDER BY 'END DATE'  DESC, 'START DATE' DESC""")

If the result is greater than 0 then you can try to see what is the output returned:-

Issues.search("""'ISSUETYPE' IN ('PERSON') AND 'STATUS' IN ('ACTIVE, INACTIVE') AND PROJECT IN ('Project1') AND 'ID NUMBER' ~ 'ID1234' ORDER BY 'END DATE'  DESC, 'START DATE' DESC""").each { issue ->
log.warn "=====>>> ${issue.key}"

}

I hope this helps to solve your question. :-)

Thank you and Kind regards,
Ram

0 votes
Jeroen Poismans
Community Champion
May 10, 2024

Hi there!

Assuming that your JQL is correct, I can only think that the executeUser does not have permission to view the issues, resulting in 0 results.

Here is what I would do:

  • Try the code with a simpler JQL, one issue (key = xxx)
  • Be sure that the executeUser has access to that issue

 

Here is a sample that worked in my istance, using the loggedIn user, that is yourself when you execute in the Script Console:

import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter

SearchService searchService = ComponentAccessor.getComponent(SearchService.class)
JqlQueryParser jqlParser = ComponentAccessor.getComponent(JqlQueryParser.class)

String JQL = "key = JIRA-1015"
def query = jqlParser.parseQuery(JQL)
def queryUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def result = searchService.search(queryUser, query, PagerFilter.getUnlimitedFilter())

return result.total

 

Jeroen