org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Edited

Hi,

I wrote a Scriptrunner postfunction that initially tries to identify the request type of a service desk ticket and then depending upon the type, performs further actions.

I was able to run the code both inline and as file script before I upgraded to 7.4.4 and now I keep getting the folllowing error when running the script either inline or via file... I can't seem to understand why it is complaining of initialization when from what I can see, it's not being initialized...Please advise...


"org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
General error during semantic analysis: Cannot set plugin module when field already initialised
java.lang.Exception: Cannot set plugin module when field already initialised
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
... 1 filtered
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:247)

For reference, here is my code
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.util.JiraUtils
import com.atlassian.jira.workflow.WorkflowTransitionUtil
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl
import com.atlassian.servicedesk.api.requesttype.RequestTypeService
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import org.apache.log4j.Level
import org.apache.log4j.Logger

/**
* This script enables automatic routing of such service desk requests that need to bybass service fulfillment review.
* The business rule to identify those requests is defined as a default value for custom field 13100.
* Created by SrivastavaA on 8/14/17.
*/

@WithPlugin("com.atlassian.servicedesk")

@PluginModule
RequestTypeService requestTypeService

def log = Logger.getLogger("scriptrunnerconsole")
log.setLevel(Level.DEBUG)

// String Constants
final String GENERAL_INQUIRIES = "General Inquiries"
final String ACCOUNTS_AND_ACCESS = "Accounts and Access"
final String PORTAL = "Portal"
final String PHONES_AND_MOBILE_DEVICES = "Phones and Mobile Devices"
final String TECHNICAL_STAFF_REQUESTS = "Technical Staff Requests"
final String COMPUTERS = "Computers"
final String FILE_TRANSFERS_AND_PRINTING = "File Transfers and Printing"
final String ASSET_MANAGEMENT = "Asset Management"
final String POLICY_AND_SECURITY = "Policy and Security"
final String SOFTWARE = "Software"

final String BUSINESS_RULES_CUSTOM_FIELD_ID = "customfield_13100" //SD Request Routing Business Rules
final String ASSIGNED_JIRA_OPERATIONS_GROUP = "customfield_13101" //Assigned JIRA Operations Group
final String SD_REQUEST_AUTOMATION_TYPE = "customfield_13102" //SD Request Automation Type

final String NG_APPS = "NotificationGroup - Applications";
final String NG_BTSG = "NotificationGroup - Business Technology Support";
final String NG_COMM = "NotificationGroup - Communications";
final String NG_DB = "NotificationGroup - Data";
final String NG_DX = "NotificationGroup - DX";
final String NG_ERP = "NotificationGroup - ERP";
final String NG_NETWKS = "NotificationGroup - Networks";
final String NG_DBO = "notifyGroup-DBOperations";

//Get Issue Object
Issue issue = issue //The issue is internally retrieved in the post-function
log.debug("Issue Key = " + issue.key)

try {
//Get Customer Request Type for Issue
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def requestType = requestTypeService.getRequestTypeForIssue(currentUser, issue).right().get()
def requestTypeName = requestType.getName()
log.debug("Request Type Name = " + requestTypeName)

//Get instance of Custom Field Manager
def customFieldManager = ComponentAccessor.getComponent(CustomFieldManager)

//Get Default Value for the Automation Business Rules Custom Field
def businessRulesObject = customFieldManager.getCustomFieldObject(BUSINESS_RULES_CUSTOM_FIELD_ID)

def fieldConfig = businessRulesObject?.getRelevantConfig(issue)
def businessRulesFieldType = customFieldManager.getCustomFieldTypes().find { it.name == "Text Field (multi-line)" }
def businessRules = businessRulesFieldType?.getDefaultValue(fieldConfig)
log.debug("Business Rules = " + businessRules.toString())

//Setup hashmap to store business rules
HashMap svcReqType2GroupMap = new HashMap<>()

String[] busRulesDefValArray = businessRules.toString().split(";")
log.debug("busRulesDefValArray SIZE = " + busRulesDefValArray.size())

for (int x = 0; x < busRulesDefValArray.size(); x++) {
String[] keyValueArray = busRulesDefValArray[x].split("[|]");
List keyValueArrayList = Arrays.asList(keyValueArray)
svcReqType2GroupMap.put(keyValueArrayList.get(0).trim(), keyValueArrayList.get(1).trim())
}

log.debug("svcReqType2GroupMap SIZE = ${svcReqType2GroupMap.size()}")

def getKeyValuePair = svcReqType2GroupMap.get(requestTypeName)
log.debug("The Key-Value Pair is = ${getKeyValuePair.toString()}")

String[] splitValues = getKeyValuePair.split(":")
def groupName = splitValues[0].trim().substring(1, (splitValues[0].trim().length() - 1))
def routingInstruction = splitValues[1].trim()

//Initialize variables to setup group picker & automation type custom field value
def groupManager = ComponentAccessor.getGroupManager()
def singleGroupCf = customFieldManager.getCustomFieldObject(ASSIGNED_JIRA_OPERATIONS_GROUP)
def automationTypeCF = customFieldManager.getCustomFieldObject(SD_REQUEST_AUTOMATION_TYPE)

return svcReqType2GroupMap.size()

 
@Looking for some guidance please@Adaptavist Supp @Jamie Echlin [Adaptavist]@Thanos Batagiannis [Adaptavist]

 

1 answer

1 accepted

Hi Anupam,

Questions like these are better suited for our support portal. We monitor our support portal continuously for problems with the plugin.

To answer your question: I believe you are experiencing a rather recent bug. SRJIRA-2388 causes @PluginModule to not correctly load classes.

The workaround is to replace @PluginModule with something like this:

RequestTypeService requestTypeService = ScriptRunnerImpl.getPluginComponent(RequestTypeService)

And you'll need this import:

import com.onresolve.scriptrunner.runner.ScriptRunnerImpl

Thanks Joshua for both answering the question and pointing me to your support portal. 

 

Let me give that a try and will update you shortly. :)

That worked. Thanks!!!

Glad to hear that it worked! If you wouldn't mind, please select my answer as the accepted answer so that others can see the solution more easily.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

358 views 0 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you