Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scriptrunner to take action on create if cloned and different action if not cloned

Julia Foden
Contributor
November 6, 2025

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

  • edit the summary and
  • add a comment to reporter 'Hi, these are the next steps . . .'

ELSE (cloned)

  • transition to cancelled/closed and
  • add a comment to reporter 'create a new ticket from create button'

The below code works in the console when I run it on a cloned or non-cloned issue.

Screenshot 2025-11-06 141629.png

 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

 

3 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
Julia Foden
Contributor
November 12, 2025

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:

  1. a Listener on the IssueLinkCreated event to transition/close the issue
  2. a Job every 10 mins searching for issues in the first workflow status which do not have a specific label. This job edits the summary, adds a comment, and adds the label (to prevent duplication)

It's not ideal because I wanted the actions in the 'happy path' (not cloned) to happen immediately on create, but it works.

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
November 10, 2025

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:-

listener.png

I hope this helps to solve your issue. :-)

Looking forward to your feedback.

Thank you and Kind regards,

Ram

 

 

Julia Foden
Contributor
November 12, 2025

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.

0 votes
Mohamed Benziane
Community Champion
November 10, 2025

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.

DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events