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)

 

 

 

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
Ravi Sagar _Sparxsys_
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 15, 2020

Hi @Mario 

1. Try this for priority.

${issue.priority.name}

2. For last comment try this.

${com.atlassian.jira.component.ComponentAccessor.getCommentManager().getLastComment(issue).body}

For  all comments try this.

${com.atlassian.jira.component.ComponentAccessor.getCommentManager().getComments(issue).collect{it.body}.join('\n')}

I hope it helps.

Ravi

Mario
June 15, 2020

Hi @Ravi Sagar _Sparxsys_ 

thank you for the fast answer. 

1. is working as expected. ;-) 

2.

${com.atlassian.jira.component.ComponentAccessor.getCommentManager().getComments(issue).collect{it.body}.join('\n')}

--> This does correctly provide all comments, but only as a single line:

13245 1324 blibla   1 bitte prüfen   alles ok done dfghjkl test test2 [^1234.txt] [^test.xlsx] test3 mit attachments test 4 + bes-support in to 123 first test scriptrunner built in mail custom

Do you see any chance how I can get all comments listed up one below each other? Best would be to have any kind of indicator when a comment ends and the next comment begins, e.g. that the comment has a "key point" indicator like "-" or s.th. similar?!

Thank you very much!

Best regards

Mario

Ravi Sagar _Sparxsys_
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 16, 2020

Try with <br>. You can also enclose this with <li> to have them displayed as a list.

Mario
June 16, 2020

Hi @Ravi Sagar _Sparxsys_ 

thank you once again.

Sorry for the dumb question but where exactly within the code 

${com.atlassian.jira.component.ComponentAccessor.getCommentManager().getComments(issue).collect{it.body}.join('\n')}

should I place "<br>" or "<li>[...]</li>?

No matter where I've tried it the preview always fails?!

Best regards

Mario

Ravi Sagar _Sparxsys_
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 18, 2020

Hi @Mario 

Try this.

<ul>
${com.atlassian.jira.component.ComponentAccessor.getCommentManager().getComments(issue).collect{ '<li>'+it.body+'</li>'}.join('<br>')}
</ul>

Make sure the email format is HTML.

I hope it helps.

Ravi

Mario
June 19, 2020

Works like a charm, thx a lot.

Here the complete code I'm using, if anybody needs it later on:

 

<% def commentManager = com.atlassian.jira.component.ComponentAccessor.getCommentManager() %>
<% def comments = commentManager.getComments(issue) %>

<ul>
<li><b>Summary:</b> ${issue.summary} </li> <br>
<li><b>Issuekey:</b> ${issue.key}</li> <br>
<li><b>Priority:</b> ${issue.priority.name}</li> <br>
<li><b>Reporter:</b> ${issue.reporter} </li> <br>
<li><b>Created Date:</b> ${issue.created} </li> <br>
<li><b>Description:</b> ${issue.description} </li> <br>
<li><b>All Comments:</b>
<ul>${com.atlassian.jira.component.ComponentAccessor.getCommentManager().getComments(issue).collect{ '<li>'+it.body+'</li>'}.join('<br>')}
</ul>
</li> <br>
<li><b>Information:</b><br>Text[...]
</li>
</ul>

TAGS
AUG Leaders

Atlassian Community Events