Could someone explain to me why this does not work?
I have a code that performs a query in the jira database and with result I execute other activities in the same script.
for example, I query in the database the issue id related to the current issue and remove the link between them. (this is just an example)
import com.atlassian.jira.component.ComponentAccessor
import groovy.sql.Sql
import org.ofbiz.core.entity.ConnectionFactory
import org.ofbiz.core.entity.DelegatorInterface
import com.atlassian.jira.config.properties.PropertiesManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.IssueLink
import java.sql.Connection
def delegator = (DelegatorInterface) ComponentAccessor.getComponent(DelegatorInterface)
String helperName = delegator.getGroupHelperName("default");
Connection conn = ConnectionFactory.getConnection(helperName);
Sql sql = new Sql(conn)
StringBuffer sb = new StringBuffer()
try {
sql.eachRow("""
select il.source from jiraissue c
left join issuelink il on il.DESTINATION = c.id
where c.project = 12100
and c.id = ${issue.id}
""") {
sb << "${it}"
}
sb.toString()
} finally {
sql.close()
}
def id = sb.replaceAll("\\[source:","").replaceAll("\\]","")
def uu = ComponentAccessor.getUserUtil()
Object user = uu.getUserByName("automacao")
def linkMgr = ComponentAccessor.getIssueLinkManager()
def sourceId = id as long
def linkType =10400 as long
def issueLink = linkMgr.getIssueLink(sourceId, issue.id, linkType);
linkMgr.removeIssueLink(issueLink, user);
This post function script works perfectly if it is executed by clicking the transition button.
But if another problem that has a script that transitions into another problem, calls the problem that has this script, several errors occur.
after a lot of head breaking I found that if a issue (issue A) performs the automatic transition in issue (issue
where it has the SQL post function, the SQL query does not work (several errors occur)
Why is this occurring?
What is the difference of the post function script being executed manually (by clicking the button on the screen) of what is automatically executed by another issue?
and the most important ...
How can I solve this? :S