You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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?
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.