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.
Community moderators have prevented the ability to post new answers.
I would try to use IssueService instead of IssueManager.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How are you searching? Paste the JQL here. The problem is, that Lucene index is not properly reindexed.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.