Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to detect if an issue is a clone in a listener at issueCreated

Brian Louks April 1, 2012

Doesn't look like there's a good way to detect what's a clone via a listener. The "Cloners" issue link apparently isn't added at the time the issueCreated event is handled by the listner.

Anyone know is there's a way to detect cloning at issue create time?

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
Dieter
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.
April 2, 2012
You could check if you find some method specific to the clone action in you stacktrace. Just add this statement to your listener: new Exception().printStackTrace() and check catalina.out
Brian Louks April 2, 2012

You're crazy man. I like you, but you're crazy. This does show up in the stack trace:

CreateIssueDetails.java com.atlassian.jira.web.action.issue.CreateIssueDetails createIssue

I don't want to do it ... but I just might! Thanks

Dieter
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.
April 2, 2012
Well, i don't mind to be crazy if it helps ;) ... Like here: https://answers.atlassian.com/questions/37167/jira-notify-on-email-ticket-creation
Brian Louks April 2, 2012

Whoops, I mean this is in the stack trace:

CloneIssueDetails.java com.atlassian.jira.web.action.issue.CloneIssueDetails doExecute

The other line I mentioned was in the stack trace, but wouldn't be very useful.

Thanks again

francis
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
June 30, 2013

Brian,

Did you find a working solution?

Francis

Brian Louks June 30, 2013

I did not find any good ways to do this, no

vinit k shah December 27, 2018

Hi Brian,

we also get this line in stacktrace. 

CloneIssueDetails.java com.atlassian.jira.web.action.issue.CloneIssueDetails doExecute

But My question, how we do get source jira issue Id from which cloned happen in jira event listener ? 

francis
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
December 27, 2018

Hi Vints

Check the comments below.  The way we solved it in the table grid editor app is by creating a new custom field 'Origin ID'  More information in the link

https://wiki.idalko.com/x/nYP4B

 

Francis

vinit k shah December 27, 2018

Thanks for quick reply. 

But we don't have provision to introduce new custom fields in jira, Is it possible with some other way ? 

Actual Problem : we are add-on vendor (Test Management) , when customer uses jira's clone functionality, our data (steps) are not copied on newly created jira issue.

0 votes
Nathon Fowlie April 27, 2014

Resurrecting an old post, but you could look at the issue links and check the outward description. Here's some sample code. I haven't tested it so it may not compile.

Issue issue = event.getIssue();
IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager();
IssueLinkTypeManager issueLinkTypeManager = ComponentAccessor.getComponent(IssueLinkTypeManager.class);
// Alternatively you could put the "Cloners" issue link type id in a constant rather than try 
// to find it by name and assuming the first list result is the one you want.
List<IssueLinkType> clonersIssueLinkTypes = issueLinkTypeManager.getIssueLinkTypesByName("Cloners");
Long cloneIssueLinkTypeId = null;

if (clonersIssueLinkTypes) {
    cloneIssueLinkTypeId = clonersIssueLinkTypes.listIterator().next().getId();
} else {
    LOG.warn("Unable to find the 'cloners' issue link type, cannot continue...");
    return; 
}
List<IssueLink> outwardLinks = issueLinkManager.getOutwardLinks(issue.getId());

if (outwardLinks) {
    for (IssueLink issueLink : outwardLinks) {
        if (issueLink.getIssueLinkTypeId() == cloneIssueLinkTypeId ) {
            // This is a cloned issue, do things and stuff.
        }
    }
}

francis
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
April 27, 2014

We actually solved it this way

http://wiki.idalko.com/display/TGPD/Behind+the+scenes+of+gd.initFromClone

Still I think this should be part of the core product.

Nathon Fowlie May 15, 2014

That's a good way to handle it. I ended up doing pretty much the exact same thing. On issue created, if "OriginID" is null, this is a brand new issue so set OriginID to the issue key of the newly created issue. If not null, then this is a clone of an existing issue, do whatever needs to be done and update OriginID.

Like francis likes this
0 votes
Brian Louks June 30, 2013

I did not find any good ways to do this, no

TAGS
AUG Leaders

Atlassian Community Events