Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

jira 7.6.0 scriptrunner 5.3.1 after updating typehandling exception

Krasina Anna
February 5, 2018

Hello! After updating scriptrunner to version 5.3.1 i'm running a script and getting the error: 

org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'com.onresolve.scriptrunner.canned.jira.utils.ConditionCustomScriptDelegate@18538353' with class 'com.onresolve.scriptrunner.canned.jira.utils.ConditionCustomScriptDelegate' to class 'com.onresolve.scriptrunner.canned.jira.utils.CustomScriptDelegate'

I included imports:

import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.transform.BaseScript
import javax.ws.rs.core.MediaType
import javax.ws.rs.core.MultivaluedMap
import com.atlassian.jira.issue.Issue
import javax.ws.rs.core.Response
import javax.ws.rs.core.Response.Status
import groovy.json.JsonBuilder
import com.atlassian.jira.project.Project
import com.atlassian.jira.user.ApplicationUser
import java.text.SimpleDateFormat
import java.sql.Timestamp;
import java.text.DateFormat
import com.onresolve.scriptrunner.canned.jira.admin.CopyProject
import com.atlassian.jira.issue.IssueManager
import groovy.json.JsonSlurper;
import groovy.json.StreamingJsonBuilder;
import groovy.json.JsonBuilder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.security.groups.GroupManager
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.event.type.EventDispatchOption

@BaseScript CustomEndpointDelegate delegate

Previously, the script was executed without errors

In the body of the script contains a call to the built-in script copyProject. Can this cause an error?   Any help will be greatly appreciated.

def copyProject = new CopyProject()
def inputs = [
(CopyProject.FIELD_SOURCE_PROJECT) : template,
(CopyProject.FIELD_TARGET_PROJECT) : key,
(CopyProject.FIELD_TARGET_PROJECT_NAME) : name,
(CopyProject.FIELD_COPY_VERSIONS) : true,
(CopyProject.FIELD_COPY_COMPONENTS) : true,
(CopyProject.FIELD_COPY_ISSUES) : true,
//(CopyProject.FIELD_COPY_GREENHOPPER) : false,
(CopyProject.FIELD_COPY_DASH_AND_FILTERS) : false,
// (CopyProject.FIELD_ORDER_BY) : "Rank",
]
def errorCollection = copyProject.doValidate(inputs, false)
if(errorCollection.hasAnyErrors()) {
return Response.status(Status.BAD_REQUEST).entity(new JsonBuilder([Res: errorCollection.toString()]).toString()).build()
}
else {
GroupManager GM = ComponentAccessor.getGroupManager()
def adminsGroup = GM.getGroup("jira-local-administrators")
assert adminsGroup // must have jira-administrators group defined
Collection<ApplicationUser> admins = GM.getUsersInGroup(adminsGroup)
assert admins // must have at least one admin
ComponentAccessor.getProjectManager().refresh()
ComponentAccessor.getJiraAuthenticationContext().setLoggedInUser(admins.first())
copyProject.doScript(inputs)

 

 

 

2 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
June 28, 2021

When I tried your script, I found that you were missing an import for the SearchService... but also, I think this can be simplified with the @JiraAgileBean notation

import com.onresolve.scriptrunner.runner.customisers.JiraAgileBean
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
@WithPlugin("com.pyxis.greenhopper.jira")
import com.atlassian.greenhopper.manager.issuelink.EpicLinkManager
@JiraAgileBean
EpicLinkManager epicLinkManager


def issuesInEpic = epicLinkManager.getIssuesInEpic(issue)
return issuesInEpic.size()

Also, in my environment, this ran in about 10ms compared to 25-30ms for your code (using the same epic with 6 issues)

And finally, your velocity template seems overly complicated, isn't the following what you are trying to achieve?

<style>
.red-epic-count { background-color: tomato; color: white; }
.green-epic-count { background-color: green; color: white; }
</style>

#set( $Integer = 0 )
#set($epicCount = $Integer.valueOf($value))
#if($epicCount > 5)
#set($class="red-epic-count")
#else
#set($class="green-epic-count")
#end
<h2 class="$class"> $value </h2>
0 votes
Rahul Jodavula
June 28, 2021

Yes same thing , Thank you very much

Your help is much appreciated.

TAGS
AUG Leaders

Atlassian Community Events