Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
badges earned

Your Points Tracker
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

NoClassDefFoundError encountered in custom JQL function Edited

I need to write a custom JQL function.
In the workflow is the stage "Waiting for approval". Each approver can individually accept/decline the issue. Some approvers are belonging to the defined group. The purpose of this function is to hide those issues in which someone from this group has already accepted/declined.
I made sure that the function body is working properly. I tested it in the script console and everything was OK. However, when I insert the function into the Adaptavist template, I get the error java.lang.NoClassDefFoundError: com / atlassian / servicedesk / api / approval / ApprovalService. Error is generated by the last line.

Any help will be really appreciated.


package com.onresolve.jira.groovy.jql

import com.atlassian.servicedesk.api.approval.ApprovalService
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.jql.operand.QueryLiteral
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.jql.query.RangeQueryFactory
import com.atlassian.jira.util.MessageSetImpl
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.query.operand.FunctionOperand
import com.atlassian.query.operator.Operator
import org.apache.log4j.Category
import com.atlassian.jira.util.MessageSet
import com.atlassian.crowd.embedded.api.User
import com.atlassian.query.clause.TerminalClause
import com.atlassian.jira.jql.query.QueryCreationContext
import org.apache.lucene.document.NumberTools
import org.apache.lucene.index.Term
import com.onresolve.jira.groovy.jql.AbstractScriptedJqlFunction
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.user.util.UserManager
import com.onresolve.scriptrunner.runner.customisers.WithPlugin

class mySGroupPendingApprovers extends AbstractScriptedJqlFunction implements JqlQueryFunction{
String getDescription() {
"Function to show only the inactive users"

List<Map> getArguments() {
"description": "Subquery",
"optional": false,

String getFunctionName() {

MessageSet validate(User user, FunctionOperand operand, TerminalClause terminalClause) {
def messageSet = new MessageSetImpl()
return messageSet

Query getQuery(QueryCreationContext queryCreationContext, FunctionOperand operand, TerminalClause terminalClause) {
JiraAuthenticationContext context = ComponentAccessor.getJiraAuthenticationContext();
ApplicationUser applicationUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
UserManager userManager = ComponentAccessor.getUserManager();
ApplicationUser actingUser = userManager.getUserByName("automat");
Class ApprClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.atlassian.servicedesk.api.approval.ApprovalService");
def approvalService = ComponentAccessor.getOSGiComponentInstanceOfType(ApprClass);
// collecting the userNames list (group)
// test code
Collection<String> userNames = ['pi24468','pi01697','pi10310','pi01498'];
// prod code
// .....

// collecting the output issue list
def booleanQuery = new BooleanQuery()
// test code
// def issues = [ComponentAccessor.getIssueManager().getIssueByCurrentKey("CHANGE-1315"),
// ComponentAccessor.getIssueManager().getIssueByCurrentKey("CHANGE-1814")];
// prod code
issues = getIssues(operand.args[0], applicationUser)
def approvalEither
def approvals
def pendingApproval
def approversEither
def approvers
def approversList
def approversDoneList

issues.each {Issue issue ->
pendingApproval = issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName('Approvals').first()).getApprovals()

if (pendingApproval) {
// found at least 1 pending approval
approversEither = approvalService.getApprovers(applicationUser, pendingApproval.first())
approvers = approversEither.isRight() ? approversEither.right : []
approversList = approvers.findAll{!it.getApproverDecision().getOrNull()}.collect{it.getApproverUser().name}
if ((approversList.size() > 0) && (approversList.intersect(userNames).size() > 0)) {
// found at least 1 pending approval for approver who belongs to group
approversDoneList = approvers.findAll{it.getApproverDecision().getOrNull()}.collect{it.getApproverUser().name}
if ((approversDoneList.size() == 0) || (approversDoneList.intersect(userNames).size() == 0)) {
// not found any approval done by approver who belongs to group
// this ticket to be shown in "ToApprove" queue
booleanQuery.add(new TermQuery(new Term("issue_id", as String)), BooleanClause.Occur.SHOULD)
}catch(NullPointerException NPE){

return booleanQuery }

// main
SearchService searchService = ComponentAccessor.getComponent(SearchService.class)
UserManager userManager = ComponentAccessor.getUserManager();
ApplicationUser actingUser = userManager.getUserByName("automat");

def jqlSearch = "issueFunction in mySGroupPendingApprovers('";
jqlSearch += 'category="Service Desk"'
jqlSearch += "')"
SearchService.ParseResult parseResult = searchService.parseQuery(actingUser, jqlSearch)
if (parseResult.isValid()) {
def searchResult =, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())


java.lang.NoClassDefFoundError: com/atlassian/servicedesk/api/approval/ApprovalService at com.onresolve.jira.groovy.jql.mySGroupPendingApprovers.getQuery(mySGroupPendingApprovers.groovy:84) at com.onresolve.jira.groovy.jql.JqlQueryFunction$ Source) at com.onresolve.jira.groovy.jql.ScriptedJqlFunction.getQuery(ScriptedJqlFunction.groovy:128) at com.onresolve.jira.groovy.jql.ScriptedJqlFunction$ Source) at com.onresolve.jira.groovy.jql.ScriptedFunctionClauseFactory.getQuery(ScriptedFunctionClauseFactory.groovy:92) at com.atlassian.jira.jql.query.ContextAwareQueryVisitor.visit( at com.atlassian.jira.jql.query.ContextAwareQueryVisitor.visit( at com.atlassian.query.clause.TerminalClauseImpl.accept( at com.atlassian.jira.jql.query.QueryVisitor.createQuery( at com.atlassian.jira.jql.query.DefaultLuceneQueryBuilder.createLuceneQuery( at at at at at at at$search$ Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall( at at at at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval( at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval( at javax.script.AbstractScriptEngine.eval( at javax.script.ScriptEngine$ Source) at com.onresolve.scriptrunner.runner.AbstractScriptRunner.runScriptAndGetContext(AbstractScriptRunner.groovy:94) at com.onresolve.scriptrunner.runner.AbstractScriptRunner$runScriptAndGetContext$2.callCurrent(Unknown Source) at com.onresolve.scriptrunner.runner.AbstractScriptRunner.runStringAsScript(AbstractScriptRunner.groovy:192) at com.onresolve.scriptrunner.runner.AbstractScriptRunner.runStringAsScript(AbstractScriptRunner.groovy) at at at sun.reflect.GeneratedMethodAccessor1607.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke( at java.lang.reflect.Method.invoke( at$ResponseOutInvoker$1.invoke( at$1.intercept( at at at at

....and many more

0 answers

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Marketplace Apps & Integrations

Staying organized with Jira: best practices for a better project management

Project managers know this problem: A “mountain of work” lays in front of you, and you don’t know how and where to tackle them. Different to-dos lie ahead, but just one task after the other can be ha...

177 views 2 1
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