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 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 _ScriptRunner - The Adaptavist Group_@Thanos Batagiannis [Adaptavist]
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. :)
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.
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.
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.