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,363,765
Community Members
 
Community Events
168
Community Groups

JQL working fine in scriptrunner except when it gets to a specific project, then it throws exception

Edited

I am running some Jira statistics in ScriptRunner and I would like to know the number of issues that were updated in the last year. My script works fine for a number of projects except when I get to 1 specific project. I get an exception and I really don't know why because the JQL query works perfectly fine for all the other projects. Here is my code below:

Here is the exception that I get:
**2022-08-25 16:16:46,273 ERROR [common.UserScriptEndpoint]: Script console script failed:
groovy.lang.MissingMethodException: No signature of method: com.sun.proxy.$Proxy128.search() is applicable for argument types: (com.atlassian.jira.user.DelegatingApplicationUser, String, com.atlassian.jira.web.bean.PagerFilter) values: [mouh(JIRAUSER65000), , com.atlassian.jira.web.bean.PagerFilter@1c986119[start=0,end=2147483647,max=2147483647]]
Possible solutions: search(com.atlassian.jira.user.ApplicationUser, com.atlassian.query.Query, com.atlassian.jira.web.bean.PagerFilter), each(groovy.lang.Closure)
at com.atlassian.jira.bc.issue.search.SearchService$search$3.call(Unknown Source)
at Script942.run(Script942.groovy:65)**

I also get the exception in my try catch statement `2022-08-25 16:16:46,258+0200 https-openssl-nio-443-exec-25 WARN mouh 976x7083017x3 15vdzc9 10.21.32.10 /rest/scriptrunner/latest/user/exec/ [atlassian-jira.log] MounaException com.atlassian.jira.jql.parser.JqlParseException: com.atlassian.jira.jql.parser.antlr.RuntimeRecognitionException: NoViableAltException(17@[])`

import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger;
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.jql.builder.JqlQueryBuilder
import com.atlassian.jira.web.bean.PagerFilter
import java.text.SimpleDateFormat
import com.atlassian.jira.project.Project
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.user.DelegatingApplicationUser
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.security.roles.ProjectRole
import com.atlassian.jira.security.roles.ProjectRoleActors
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.issue.search.SearchException

def log = Logger.getLogger("atlassian-jira.log")

List<Project> prList = ComponentAccessor.getProjectManager().getProjectObjects()
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def issueManager = ComponentAccessor.getIssueManager()
def projectManager = ComponentAccessor.projectManager
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)

log.warn("Project category|Project name|Last Date Updated| Number of issues|Project Lead|Admin List")
def searchService = ComponentAccessor.getOSGiComponentInstanceOfType(SearchService.class)
ApplicationUser user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()

def emptyList = []

for(Project myproject: prList){
def lastUpdatedDate = new Date(Long.MIN_VALUE)
def builder = JqlQueryBuilder.newBuilder()
builder.where().project(myproject.id)
def query = builder.buildQuery()
def results = searchService.search(user, query, PagerFilter.getUnlimitedFilter())

def lastUpdated =""
if (results.getTotal() == 0) {
emptyList.add(myproject.getName())
log.warn("Empty project")
}
else {

def i = 0
for (Issue issue : results.getResults())
{
lastUpdated = issue.getUpdated()
if (i == 0 || lastUpdated > lastUpdatedDate)
lastUpdatedDate = lastUpdated
i++
}
log.warn("project key: "+myproject.getKey())
def query2 = ""
try{
query2 = jqlQueryParser.parseQuery("project = "+myproject.getKey()+" and updated < 2021-08-25 ")

}catch(Exception e){
log.warn("MounaException "+e)
}

def search = searchService.search(user, query2, PagerFilter.getUnlimitedFilter())
log.warn("Updated issues in the last year: ${search.total}"+" project "+myproject.getKey()+"/"+results.getTotal() )





}

def projectCategory=""
if(myproject.getProjectCategory()!=null){
projectCategory=myproject.getProjectCategory().getName()
}

def admins= getAdmins(projectRoleManager, myproject, user, projectManager)
def lastDate= new SimpleDateFormat("dd/MMM/yy").format(lastUpdatedDate)
log.warn("oo|"+projectCategory+"|"+myproject.getName()+"|"+lastDate + "|"+results.getResults().size() + "|"+ myproject.getProjectLead().getName() +"|"+admins)


}
log.warn("Empty projects: "+ emptyList.size()+"/"+prList.size() +" "+emptyList)


def getAdmins(ProjectRoleManager projectRoleManager, Project myproject, ApplicationUser user, ProjectManager projectManager ){


def adminProjects = []

ProjectRole projectRole = projectRoleManager.getProjectRole("Administrators")

def projectRoles = projectRoleManager.getProjectRoles(user, myproject)
Project project = projectManager.getProjectObjByKey(myproject.getKey())
def result =""
if (project) {
ProjectRoleActors actors = projectRoleManager.getProjectRoleActors(projectRole, project)
result += " ${actors.getUsers()*.name}\n"
}
return result

}

 

 

Here is a copy of my log file where I am doing all the printing as you can see, everything works fine except when I get to the CF project. Anyone knows what should be fixed? I have tried using project.getName() in my query instead of project.getKey() and nothing changed, still not working


2022-08-25 16:16:46,258 WARN [atlassian-jira.log]: project key: CF
2022-08-25 16:16:46,258 WARN [atlassian-jira.log]: MounaException com.atlassian.jira.jql.parser.JqlParseException: com.atlassian.jira.jql.parser.antlr.RuntimeRecognitionException: NoViableAltException(17@[])
2022-08-25 16:16:46,273 ERROR [common.UserScriptEndpoint]: *************************************************************************************
2022-08-25 16:16:46,273 ERROR [common.UserScriptEndpoint]: Script console script failed:
groovy.lang.MissingMethodException: No signature of method: com.sun.proxy.$Proxy128.search() is applicable for argument types: (com.atlassian.jira.user.DelegatingApplicationUser, String, com.atlassian.jira.web.bean.PagerFilter) values: [mouh(JIRAUSER65000), , com.atlassian.jira.web.bean.PagerFilter@1c986119[start=0,end=2147483647,max=2147483647]]
Possible solutions: search(com.atlassian.jira.user.ApplicationUser, com.atlassian.query.Query, com.atlassian.jira.web.bean.PagerFilter), each(groovy.lang.Closure)
at com.atlassian.jira.bc.issue.search.SearchService$search$3.call(Unknown Source)
at Script942.run(Script942.groovy:65)



 

 

 

1 answer

0 votes

Hi,

It seems that CF is not accepted by Jira when it is used in a JQL. Try to add quotation mark around CF like this:

Community.pngCommunity2.png

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events