Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Exceptions trying to delete issues via Groovy

Hello,

i had a piece of code that worked just fine when deleteing subtasks.

Now i am trying to delete standard issues and i can't get it to work.

I have tried two ways of deleting them:

 

package sandbox

import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.search.SearchResults
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.web.bean.PagerFilter

IssueManager issueManager = ComponentAccessor.getIssueManager()
Issue invoiceIssue = issueManager.getIssueByKeyIgnoreCase("DBH-439")

ApplicationUser runAsUser = ComponentAccessor.getUserManager().getUserByKey("admin")

def getIssueListByJql = { String jql ->
SearchService searchService = ComponentAccessor.getComponent(SearchService.class)
SearchService.ParseResult parseResult = searchService.parseQuery(runAsUser, jql);
if (parseResult.isValid()) {
SearchResults searchResult = searchService.search(runAsUser, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
return searchResult.getIssues();
} else {
throw new Exception("invalid jql:" + jql)
}
}

Iterator iterator = getIssueListByJql("summary ~ \"|" + invoiceIssue.getKey() + "|\" AND project = PAGE AND issueType = Seite").iterator()

Boolean workaround = true
while (iterator.hasNext()) {
Issue issue = (Issue) iterator.next()
log.error "To DEL " +issue.getKey() + "," + runAsUser + "," + issue + "," + EventDispatchOption.ISSUE_DELETED + "," + issueManager
Issue issueToDelete = issue
if (workaround) {
issueToDelete = issueManager.getIssueByKeyIgnoreCase(issue.getKey())
}
issueManager.deleteIssue(runAsUser, issueToDelete, EventDispatchOption.DO_NOT_DISPATCH, false)
log.error "DELETED " +issue.getKey()
}

When i run this one i get

groovy.lang.GroovyRuntimeException: Ambiguous method overloading for method com.atlassian.jira.issue.managers.RequestCachingIssueManager#deleteIssue. Cannot resolve which method to invoke for [class com.atlassian.jira.user.DelegatingApplicationUser, null, class com.atlassian.jira.event.type.EventDispatchOption$EventDispatchOptionImpl, class java.lang.Boolean] due to overlapping prototypes between: [interface com.atlassian.jira.user.ApplicationUser, interface com.atlassian.jira.issue.Issue, interface com.atlassian.jira.event.type.EventDispatchOption, boolean] [interface com.atlassian.jira.user.ApplicationUser, interface com.atlassian.jira.issue.MutableIssue, interface com.atlassian.jira.event.type.EventDispatchOption, boolean] at sandbox.Script157.run(Script157.groovy:38)

 

When i set workaound to false i get 

 java.lang.UnsupportedOperationException: Cannot remove an ImmutableGenericValue at com.atlassian.jira.util.ofbiz.ImmutableGenericValue.remove(ImmutableGenericValue.java:36) at com.atlassian.jira.issue.managers.DefaultIssueDeleteHelper.deleteIssue(DefaultIssueDeleteHelper.java:143) at com.atlassian.jira.issue.managers.DefaultIssueManager.deleteIssue(DefaultIssueManager.java:717) at com.atlassian.jira.issue.managers.RequestCachingIssueManager.deleteIssue(RequestCachingIssueManager.java:225) at com.atlassian.jira.issue.IssueManager$deleteIssue$4.call(Unknown Source) at sandbox.Script159.run(Script159.groovy:38)

 

Any ideas?

 

Please help me Atlassian Community, you are my only hope

3 answers

1 accepted

0 votes
Answer accepted

I tried your code and it worked fine for me with workaround turned on, with workaround off I got same error you got (but I guess it's expected)

But for your first exception, it seems like it can't find issueToDelete. Try executing this:

issueManager.deleteIssue(runAsUser, null, EventDispatchOption.DO_NOT_DISPATCH, false)

and you'll see same error.

My best guesses would be:

1. log exactly issueToDelete to see if it's not null

2. reindex project, maybe that's why you are getting null issue objects

Hi Ilya, 

thanks for the fast answer,

i seem to have some "broken" issues in my issue index,

they still appeared in the issue search after deleting them via the jira UI until reindexing

 

kind regards

Jens

It seems to be an issue that surfaces from time to time, 

in about one of ten tries i am generating these broken issues appear. Strange...

At one point i got another even more weird exception, but i can't reproduce that now:

2019-07-03 10:57:04,778 http-nio-127.0.0.1-8080-exec-85 ERROR admin 657x15478x1 mjhtgh 80.147.223.246,127.0.0.1 /rest/scriptrunner/latest/user/exec/ [c.o.scriptrunner.runner.ScriptRunnerImpl] To DEL PAGE-20,admin(admin),DocumentIssueImpl[issueKey=PAGE-20],com.atlassian.jira.event.type.EventDispatchOption$EventDispatchOptionImpl@652f8345,com.atlassian.jira.issue.managers.RequestCachingIssueManager@54a6a389
at postFunctionDeleteInvoicePages.run(postFunctionDeleteInvoicePages.groovy:27)
at com.atlassian.jira.issue.IssueManager$deleteIssue$4.call(Unknown Source)
at com.atlassian.jira.issue.managers.RequestCachingIssueManager.deleteIssue(RequestCachingIssueManager.java:225)
at com.atlassian.jira.issue.managers.DefaultIssueManager.deleteIssue(DefaultIssueManager.java:717)
at com.atlassian.jira.issue.managers.DefaultIssueDeleteHelper.deleteIssue(DefaultIssueDeleteHelper.java:120)
at com.atlassian.jira.issue.managers.DefaultIssueDeleteHelper$DeletedIssueEventData.<init>(DefaultIssueDeleteHelper.java:274)
java.lang.NullPointerException

Due to further changes in JIRA's available methods, I updated the script to the below:

import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.search.SearchResults
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.web.bean.PagerFilter

IssueManager issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def getIssueListByJql = { String jql ->
SearchService searchService = ComponentAccessor.getComponent(SearchService.class)
SearchService.ParseResult parseResult = searchService.parseQuery(user, jql);

if (parseResult.isValid()) {
SearchResults searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
return searchResult.getResults();
} else {
throw new Exception("invalid jql:" + jql)
}
}

Iterator iterator = getIssueListByJql("<your JQL>").iterator()

Boolean workaround = true
while (iterator.hasNext()) {
Issue issue = (Issue) iterator.next()
log.error "To DEL " +issue.getKey() + "," + user + "," + issue + "," + EventDispatchOption.ISSUE_DELETED + "," + issueManager
Issue issueToDelete = issue
if (workaround) {
issueToDelete = issueManager.getIssueByKeyIgnoreCase(issue.getKey())
}
issueManager.deleteIssue(user, issueToDelete, EventDispatchOption.DO_NOT_DISPATCH, false)
log.error "DELETED " +issue.getKey()
}

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you