ScriptRunner - Identify Cloned Issues via Listener

Roberto L
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 28, 2019

hello Community,

Is there a way to have a listener trigger when an issue is cloned.

I do not see issue clone as one of the Events you can associate to a listener.

I am aware that a "CLONE" triggers a "CREATE", would there be a way to check the issue on create for a specific attribute that signifies that it was cloned as opposed to created?

Any help is much appreciated!

-Roberto

1 answer

4 votes
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 3, 2019

You are correct that you can only listen for CREATE event.

And I think that if your cloning process doesn't include either a summary prefix or clonners linked issue type, then there might not be anything in the event that will identify this as a clone.

Basically, if you can't tell from looking at any attribute of the issue that it was a clone rather than fresh ticket, then there is no way to know in the listener.

Roberto L
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 10, 2019

Hi @Peter-Dave Sheehan ,

The cloned issue has the issue linked of "cloned by" that JIRA appends.

This is my code for trying to pick up when something is cloned: 

Issue issue = event.issue
UserManager userManager = ComponentAccessor.getComponent(UserManager)

def clonedIssues = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId())?.findAll {it.issueLinkType.outward == "Cloners"};

if (clonedIssues) {
//Do all the processing I need to do since this is a cloned issue
}

 Utilizing the above code I still cant seem to target only the issues that are created through clone as opposed to just naturally created.

Do you see anything faulty in code or is there a different way to asses?

The prefix of "clone" is not reliable since users can replace it before they initiate clone.

Thanks for the help!

-Roberto

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 19, 2019

IssueLinkType have 3 main attributes: name, outward description and inward description.

Looks like you were looking at the value of the outward description and comparing it to the string that matches the name.

Try either:

def clonedIssues = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId())?.findAll {it.issueLinkType.name == "Cloners"}

or

def clonedIssues = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId())?.findAll {it.issueLinkType.outward == "clones"}
nnallusamy September 1, 2020

Hi @Peter-Dave Sheehan , I have added the above code to Post-function of create transition to identify the CLONED issues and do come operation based on that. 

But, It always returns EMPTY [] list. Is there any other way to do it (except listener)? 

John W October 30, 2020

@Peter-Dave Sheehan, I also cannot get any cloner links in the Create transition.  I added a post function at the very end of the transition, after the Create Event is fired, just to log this:

linkMgr.getLinkCollectionOverrideSecurity(issue).getAllIssues()

But it never returns cloner links even when the issue has them.  If I run that same line in the console to check the new cloned issue, it returns the cloner link.  But not in the Create transition.  It sure would be nice to know if that's intentional or a bug!

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 30, 2020

I think the sequence of operation when cloning an issue is:

  1. Start Create Transition
    1. Run Create Validator
    2. Run Create Post Function
      1. Launches the IssueCreatedEvent
  2. Create Issue Link
    1. Launches the IssueLinkCreatedEvent

So you might have more luck with a listener that listens to the issueLinkCreated event.

Like Reno likes this
John W November 3, 2020

Thanks, Peter-Dave, that's very helpful, and a Listener does indeed work.

Suggest an answer

Log in or Sign up to answer