Why is it impossible to create scripted deletes?

All, I have tried this several different ways, but it seems impossible, and I am having trouble understanding why. What I want is for new issues being automatically created based on emails to go through a couple of different scripted processing functions. For a simple example:

  1. Email comes in and new issue created
  2. On the create transition see if the issue matches a couple things.
    1. If No, just leave it.
    2. If yes, fast-track the issue to transitionB.
  3. In transitionB, do the following:
    1. clone the issue to a new project as a issuetypeZ.
    2. delete the original issue

What I have tried so far is putting all of the above into post functions in transitions. This does not work. When I try to create an issue while 3b is implemented, if I manually create an issue which will match 2b, then I get this error message: "We can't create this issue for you right now, it could be due to unsupported content you've entered into one or more of the issue fields. If this situation persists, contact your administrator as they'll be able to access more specific information in the log file." If I remove that one step, then everything else works fine. The issue I created will:

  • End up in the status that follows transitionB.
  • Will create a clone of itself in the new project as intended.
  • Include a link to the cloned issue.

I have also tried taking 3b out, and making it an event listener. Instead what I do in step 3 above is modify the issue summary to include a flag to denote the issue needs to be removed. My reason for moving this to a listener was a guess that I could not a delete a thing as it was being created (which I am still not doing really, but whatever . . .). If I put it in a listener then I am saying okay, wait till this thing is created, transitioned, and the new issue cloned from it. THEN, listen for the last issue updated event, and then do the delete. Like this would be a completely separate, stand-alone task. However, I get the same message as above no matter what.

It seems that there is no way to automatically delete issues at least not when the chain of events leading to that starts from a series of automated actions initiated during the Create transition. Can anyone shed some light on this?

1 answer

Sorry, I am using ScriptRunner, by the way. The listener is:

// *****************************************************
// **   Perform required imports
// *****************************************************
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.security.JiraAuthenticationContext
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.user.util.UserManager
import java.util.regex.Matcher
import java.util.regex.Pattern
import com.atlassian.jira.bc.issue.IssueService.CreateValidationResult
import com.atlassian.jira.bc.issue.IssueService.DeleteValidationResult
import com.atlassian.jira.bc.issue.IssueService.IssueResult
import com.atlassian.jira.util.ErrorCollection
// get all of the Managers you need (or core components) UserManager userMgr = ComponentAccessor.getUserManager();
UserManager userMgr = ComponentAccessor.getUserManager()
IssueService issueSvc = ComponentAccessor.getIssueService()  //Get an Issue Manager
ApplicationUser svcUser = userMgr.getUserByName("svc-jira")
IssueManager issueMgr = ComponentAccessor.getIssueManager()
MutableIssue issue = issueMgr.getIssueObject(event.issue.getId())
Matcher deleter = issue.summary =~ /^REMOVE THIS ISSUE/
assert deleter instanceof Matcher  // Check if this is an issue to be deleted
if (deleter) {
    DeleteValidationResult delValidationResult = issueSvc.validateDelete(svcUser, issue?.id)
    log.error delValidationResult.isValid()
    if (delValidationResult.isValid()) {
        try {
            ErrorCollection deleteResult = issueSvc.delete(svcUser, delValidationResult, EventDispatchOption.ISSUE_UPDATED, false)
            log.error "The issue with ID " + issue.id + " and key " + issue.key + " has been deleted."
        } catch (e) {
            log.error e.toString()
            log.error e.getMessage()
            log.error e.getStackTrace()
        }
    } else {
        ErrorCollection errors = delValidationResult.getErrorCollection()
        log.error errors.getErrorMessages()
        log.error errors.getErrors()
    }
}

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Sunday in Agility

You asked for it, so we delivered: images on issues have arrived

A picture tells a thousand words. And agility boards have just released their latest feature: cover images on issues – so now your board can tell a story at first glance. Upload attachmen...

971 views 3 12
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