Hi
I am trying to use Scriptrunner to perform an action when an issue is created if it is cloned and a different action if it is not cloned. What I want to do is:
When created:
IF not cloned
ELSE (cloned)
The below code works in the console when I run it on a cloned or non-cloned issue.
But I can't get it to work for real.
I tried it in a workflow post-function on the Create transition (the only difference is the def issue line is not included) and the IF always ran even if the issue was cloned.
I tried it as a Listener on the Issue Created event (the only difference was the def issue line became def issue = event.issue) but the result was the same.
It seems the code is running before the clone link has been added ??
Any advice what I can do instead? I considered a listener on 'IssueLinkCreatedEvent' but the problem there would be that I'd need a separate listener to run on create for the non-cloned actions but it would run on all issues including cloned and then I'd have two contradictory comments to the reporter.
Thanks in advance, and any general advice about improving the code is welcome too
Julia
I had also asked this in Scriptrunner Loop and received an answer there. I am posting it here in case it's useful to anyone else, with thanks to Dan of Scriptrunner.
The problem is that it's a two step process: the issue is created and then the clone link is added. So Dan suggested two scripts which I have implemented as:
It's not ideal because I wanted the actions in the 'happy path' (not cloned) to happen immediately on create, but it works.
Hi @Julia Foden
The reason your Listener code is not working is because you are using the wrong event type.
When working with Issue Links, you must use either the IssueLinkCreatedEvent or the IssueLinkDeletedEvent.
It will not trigger the Listener when using the Issue Created or Issue Updated Event.
Below is a sample working code for your reference:-
import com.atlassian.jira.event.issue.link.IssueLinkCreatedEvent
def issueLinkCreated = event as IssueLinkCreatedEvent
def issueLink = issueLinkCreated.issueLink
def sourceIssue = issueLink.sourceObject
if (issueLink.issueLinkType.name == 'Cloners') {
sourceIssue.update {
setDescription('This is a cloned issue. It will by default be transitioned to done')
}
sourceIssue.transition('Done')
} else {
sourceIssue.update {
setDescription('This is not a clone and will be updated')
}
}
Please note that the sample working code above is not 100% exact to your environment. Hence, you must make the required modifications.
Below is a screenshot of the Listener configuration:-
I hope this helps to solve your issue. :-)
Looking forward to your feedback.
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ram
Thanks for your reply but the problem there is that if there is no clone link added, there will be no IssueLinkCreatedEvent so the Listener will not fire. I would need two separate listeners, as I said in my original question.
I've added the suggestion I got from Scriptrunner Loop which was to use two scripts: a Listener and a Job.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I think this is not working in a post function because the clone link is not there yet. I believe Jira creates the issue first, then adds the link after creation.
You can check this by cloning an issue and looking at the History tab — you should see two activities: the creation and the link. You could also verify this by calling the IssueLinkManager method IssueLinkManager (Atlassian JIRA 7.6.1 API). If the return is empty it should be because the link is not created yet.
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.