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 B) 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
@Orkun Gedik ... @MoroSystems Support
maybe this will help understand what I'm trying to do ...
order of activities
Issue A (active in screen)
Clicking on the transition button happens:
automatic transition in issue B
Issue B (inactive in screen)
postfuncion: a current issue is cloned (issue B)
Issue C (clone of issue B)
create postfuncion:
Code above containing SQL query (several errors occur)
I guess the error is in the parameter entered in SQL query.
I inform the issue.id, but since it is not the active issue on the screen, the issue.id informed in SQL is not correct (and the various errors occur).
Now the question is ...
how to pass the issue.id of an issue that was automatically cloned and not active on the screen?
Hi Dante, I think that it is what @Orkun Gedik says. If you're trying to use 'issue' property in postfunction on Create transition, than you should set it to the bottom of the list of the postfunctions. Can you post a printscreen of your "Create" transition's postfunctions configuration?
I remember there can be still some problems with scripts on create transition and workaround is to:
Martin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Martin
good idea
put a Fast-track after creating the issue for a transition from the first status to the first status (loop) and in this transition put the SQL script.
As soon as I carry out the suggested test I inform the result.
very grateful for the idea!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Mr.Dante,
I think your problem is getting current issue. As you said, script console works fine because your are giving an issue correctly to your script yet if you have placed your script with incorrect order into postfunctions then your script cannot to work on correct issue.
What is the position of this script in postfunctions? Can you please move your script to end, if it's not, and try again.
Regards
Orkun Gedik
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.
Hi, can you post the errors?
Martin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I noticed that the errors are in the lines that has the variable that SQL should bring ...
I did a test and manually entered in the script the id, issuekey (all values that SQL should bring) and everything worked as it should.
this proved to me that the postfunction is correct, the problem is in the SQL query (I think the issue.id used in the query is not the issue.id of the correct issue but the active issue)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.