Hi
Im trying to run this script described here
I want to add organizations from objects in Insight but I get the following errors
GroovyInsightException: startup failed: Script1.groovy: 6: unable to resolve class com.atlassian.servicedesk.api.organization.OrganizationService @ line 6, column 1. import com.atlassian.servicedesk.api.organization.OrganizationService ^ Script1.groovy: 7: unable to resolve class com.atlassian.servicedesk.api.organization.OrganizationsQuery @ line 7, column 1. import com.atlassian.servicedesk.api.organization.OrganizationsQuery ^ Script1.groovy: 5: unable to resolve class com.atlassian.servicedesk.api.ServiceDeskManager @ line 5, column 1. import com.atlassian.servicedesk.api.ServiceDeskManager ^ Script1.groovy: 9: unable to resolve class com.onresolve.scriptrunner.runner.customisers.WithPlugin @ line 9, column 1. import com.onresolve.scriptrunner.runner.customisers.WithPlugin ^ Script1.groovy: 8: unable to resolve class com.onresolve.scriptrunner.runner.customisers.PluginModule @ line 8, column 1. import com.onresolve.scriptrunner.runner.customisers.PluginModule ^ 5 errors '
Hi @Torbjörn Richter ,
In post I see many comments. Could You please show how look your script finally?
B.R.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.servicedesk.api.ServiceDeskManager
import com.atlassian.servicedesk.api.organization.OrganizationService
import com.atlassian.servicedesk.api.organization.OrganizationsQuery
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import org.apache.log4j.Level
log.setLevel(Level.INFO)
@WithPlugin("com.atlassian.servicedesk")
@PluginModule
ServiceDeskManager serviceDeskManager
@PluginModule
OrganizationService organizationService
MutableIssue issue = issue
def sdUser = ComponentAccessor.getUserManager().getUserByKey('jiraadmin')
def serviceDeskProject = serviceDeskManager.getServiceDeskForProject("Customer Support")
//get SD ID
def serviceDeskId = serviceDeskProject?.right()?.get()?.id as Integer
//Build Org Query
def organizationsQuery = organizationService.newOrganizationsQueryBuilder().serviceDeskId().build()
// get all the organizations configured for the project
def organizationsToAdd = organizationService.getOrganizations(sdUser, organizationsQuery)?.right()?.get()?.results
def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName('Organizations')
def existing = cf.getValue(issue)
for (organization in organizationsToAdd){
if (organization.toString() == 'testOrg'){
if(!existing.isEmpty()){
if(!existing.contains(organization)){
existing.add(organization)
cf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf), existing), new DefaultIssueChangeHolder())
log.info("Organization Added!")
}
else if(existing.contains(organization)){
log.info("Organization Already Exists!")
return
}
}
else{
cf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf), [organization]), new DefaultIssueChangeHolder())
log.info("Organization Set!")
}
}
}
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.