Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to properly delete issues using groovyrunner in Jira 6.2?

Alfonso Leiva October 23, 2014

In a JIRA workflow postfunction I am using groovy to get a list of issues that are linked from the issue on beeing transitioned.

The operation I succesfully need to do is to delete those issues linked by the issue in transition. The code I have works, but not properly, because after the transition, the issues are listed when searched, but if I click on them it says the issue I'm trying to see does not exists.

The code I'm using by now is the following, and I have a couple of line commented which I have used in different approaches.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUsers
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.util.ImportUtils

def productoID = 'customfield_11102'

def cfm = ComponentAccessor.getCustomFieldManager()
def ilm = ComponentAccessor.getIssueLinkManager()
def um = ComponentAccessor.getUserManager()
def im = ComponentAccessor.getIssueManager()
def iim = ComponentAccessor.getIssueIndexManager()

def productoCF = cfm.getCustomFieldObject(productoID)

def issuenew = transientVars.get("issue")

def productoOld = productoCF.getValue(issue)
def productoNew = issuenew.getCustomFieldValue(productoCF)

String tipoProdOld = productoOld.get(null)
String prodOld = productoOld.get("1")
String tipoProdNew = productoNew.get(null)
String prodNew = productoNew.get("1")

if(!tipoProdOld.equals(tipoProdNew) || !prodOld.equals(prodNew)){

  String userstring = 'alloweduser'
  def user = um.getUserByName(userstring)
  def usercrowd = ApplicationUsers.toDirectoryUser(user)
  def accionCollection = ilm.getLinkCollection(issue, usercrowd)
  def acciones = accionCollection.getOutwardIssues("Link name")
  if(null != acciones && !acciones.isEmpty()){
    def issuelinks = ilm.getOutwardLinks(issue.id)
    issuelinks.each{
      ilm.removeIssueLink(it, usercrowd)                                                           
    }
    //acciones.each {
    def iterator = acciones.iterator()
    while(iterator.hasNext()){
      def it = iterator.next()
      boolean wasIndexing = ImportUtils.isIndexIssues()
      ImportUtils.setIndexIssues(true)
      iim.deIndex(it)
      im.deleteIssue(usercrowd, it, EventDispatchOption.ISSUE_DELETED, false)             
      //iim.reIndex(it)
      //iim.deIndex(it)
      ImportUtils.setIndexIssues(wasIndexing)
    }
  }
}

Any help is welcome.

 

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Jozef Kotlár
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 Leaders.
October 23, 2014

I would try to use IssueService instead of IssueManager.

Alfonso Leiva October 23, 2014

Ok, noted, not tested yet. I will test it ASAP.

Alfonso Leiva October 26, 2014

Jozef Kotlár I changed the code and replaced

im.deleteIssue(usercrowd, it, EventDispatchOption.ISSUE_DELETED, false)

 with the following lines, but I keep having the same problem: it deletes the issue, but it list it on the search tho.

def deleteValidation = ise.validateDelete(usercrowd, it.id)

ise.delete(usercrowd, deleteValidation)

Jozef Kotlár
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 Leaders.
October 26, 2014

How are you searching? Paste the JQL here. The problem is, that Lucene index is not properly reindexed.

TAGS
AUG Leaders

Atlassian Community Events