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

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,559,321
Community Members
 
Community Events
184
Community Groups

Problems resolving/importing custom groovy classes with Insight automation script

Edited

Hi.

I have a custom class: "com.onresolve.jira.groovy.methods.IssueSearch":

package com.onresolve.jira.groovy.methods
. . .

public class IssueSearch{

.
.
.

}

 

Importing it works fine in other groovy scripts used in scheduler jobs, workflow post-functions etc., like as you would expect:

import com.onresolve.jira.groovy.methods.IssueSearch 

 

yet when using the script for a Jira Insight automation (THEN "execute groovy script")
I get this error:

unable to resolve class com.onresolve.jira.groovy.methods.IssueSearch

 

Also getting the same error when importing:

import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin 

unable to resolve class com.onresolve.scriptrunner.runner.customisers.WithPlugin
unable to resolve class com.onresolve.scriptrunner.runner.customisers.PluginModule

 

So what gives? Why is this happening?

1 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.
Aug 21, 2022

That's normal.

The insight groovy implementation is different and separate from the scriptrunner one.

As far as I know, unless they are explicitly exported, plugin classes are only available within the plugin itself.

Scriptrunner does some special things (all a bit esoteric to me) with script root etc to make your custom class available within the context of that plugin.

The only way I know to load a custom class such as that is with code like this:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.util.JiraHome

def jiraHome = ComponentAccessor.getComponentOfType(JiraHome).home
def classLoader = new GroovyClassLoader(getClass().classLoader)
def classFile = new File("$jiraHome/scripts/com/onresolve/jira/groovy/methods/IssueSearch.groovy")
Class IssueSearch = classLoader.parseClass(classFile)

If your script home is different, adjust accordingly.

Similarly, the PluginModule and WithPlugin classes and anything else in the com.onresolve.scriptrunner package will not be available by default to the Insight plugin or any insight groovy scripts.

So if your custom IssueSearch class uses PluginModule or WithPluggin, that won't work, the Insight groovy compiler will not be able to access those.

You'll need to use native jira ways to access those components.

For example, this works int he insight console to get JSM request Types for service desk with id=1:

import com.atlassian.jira.component.ComponentAccessor
Class RequestTypeService = ComponentAccessor.pluginAccessor.classLoader.findClass("com.atlassian.servicedesk.api.requesttype.RequestTypeService");
def requestTypeService = ComponentAccessor.getOSGiComponentInstanceOfType(RequestTypeService)

def queryBuilder = requestTypeService.newQueryBuilder()
queryBuilder.requestOverrideSecurity(true)
queryBuilder.serviceDesk(1)

requestTypeService.getRequestTypes(null, queryBuilder.build()).results

 The same in scriptrunner would look like this:

import com.atlassian.servicedesk.api.requesttype.RequestTypeService
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin

@WithPlugin("com.atlassian.servicedesk") sdPlugin
@PluginModule RequestTypeService requestTypeService

def queryBuilder = requestTypeService.newQueryBuilder()
queryBuilder.requestOverrideSecurity(true)
queryBuilder.serviceDesk(1)

requestTypeService.getRequestTypes(null, queryBuilder.build()).results

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events