Hey All,
The script below returns a list of Organizations attached to a Service Desk Project.
The script works perfectly fine within scriptrunner, however fails to run within Groovy.
The Error that I get is:
java.lang.NullPointerException: Cannot invoke method getOrganizations() on null object
org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:91) org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:43) org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:34) org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:115) org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:135) script1566299369126730399913.run(script1566299369126730399913.groovy:47)
The script is as follows:
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.servicedesk.api.ServiceDeskManager
import com.atlassian.servicedesk.api.organization.OrganizationsQuery
import com.atlassian.servicedesk.api.organization.OrganizationService
import com.atlassian.servicedesk.api.util.paging.SimplePagedRequest
import com.atlassian.servicedesk.api.util.paging.LimitedPagedRequest
import com.atlassian.servicedesk.api.util.paging.LimitedPagedRequestImpl
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
@WithPlugin("com.atlassian.servicedesk")
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
@WithPlugin("com.atlassian.servicedesk")
@PluginModule
ServiceDeskManager serviceDeskManager
@PluginModule
OrganizationService organizationService
def serviceDeskId = 16 as Integer
// get the available organizations for that project
def organizationsQuery = new OrganizationsQuery() {
@Override
Optional serviceDeskId() {
Optional opt = Optional.of(serviceDeskId);
return opt
}
@Override
LimitedPagedRequest pagedRequest() {
return new LimitedPagedRequestImpl(0, 50, 100)
}
}
// get all the organizations configured for that project
log.info((String)currentUser)
log.info((String)organizationsQuery)
def organizationsToAdd = organizationService.getOrganizations(currentUser, organizationsQuery)?.toList()
log.error(organizationsToAdd.getClass())
return organizationsToAdd
currentUser returns the logged in user(me)
organizationsQuery returns:
script1566299369126730399913$1@ad6a688
Does anyone have an idea how i can get around this error, or what i'm doing wrong?
Thanks in adviced,
Hi Ruben,
the @WithPlugin and @PluginModule annotations are specific to ScriptRunner. They are likely not showing as errors because you also have ScriptRunner installed on your Jira instance.
The problem with your script is that you need to initialize the serviceDeskManager and organizationServicevariables (which in ScriptRunner are initialized by @PluginModule). This is done using the getComponent global function:
ServiceDeskManager serviceDeskManager = getComponent(ServiceDeskManager) OrganizationService organizationService = getComponent(OrganizationService)
Thanks David a lot :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.