How to detect if a new issue is a clone issue

I need to detect if a new issue is a clone issue.

Although I can’t use the listener for it. The “Cloners” issue link isn’t added at the time the issueCreated event is handled by the listener and and I haven’t IssueLinkCreatedEvent because the Jira version is 7.2.
I tried to do post function for step Create. It executes last after “Fire a Issue created event that can be processed by the listener”, Although, issue link isn’t added at this time yet too.


@Scanned
public class TestFunction extends AbstractJiraFunctionProvider {
private IssueLinkManager issueLinkManager;
private static final Logger logger = LoggerFactory.getLogger(TestFunction.class);

public TestFunction(CustomFieldManager customFieldManager) {
    this.issueLinkManager = ComponentAccessor.getIssueLinkManager();
}

@SuppressWarnings("rawtypes")
@Override
public void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException {

    try {
        MutableIssue mutableIssue = getIssue(transientVars);
        if (mutableIssue == null) {
            return;
        }

        logger.debug("mutableIssue.getKey() = " + mutableIssue.getKey());
        logger.debug("mutableIssue.getId() = " + mutableIssue.getId());
        logger.debug("getInwardLinks size = " + ComponentAccessor.getIssueLinkManager().getInwardLinks(mutableIssue.getId()).size());
        logger.debug("getOutwardLinks size = " + ComponentAccessor.getIssueLinkManager().getOutwardLinks(mutableIssue.getId()).size());

        ApplicationUser  applicationUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();

        logger.debug("applicationUser.getUsername() = " + applicationUser.getUsername());

        LinkCollection linkCollection = ComponentAccessor.getIssueLinkManager().getLinkCollection(
                mutableIssue,
                applicationUser);

        logger.debug("linkCollection.getLinkTypes().size()  = " + linkCollection.getLinkTypes().size());
        logger.debug("linkCollection.getAllIssues().size()  = " + linkCollection.getAllIssues().size());
    }

    catch(Exception exception) {
        logger.error("exception = ", exception); 

    }
}
}

It returns no links.

Any solution?

Hi,
I think it’s not possible to get desired information in ‘Create’ workflow step postfunction.

But there is some workaround - create new CF, add posfunction to ‘Create’ step which sets new CF with issue ID of created issue (has to be before your postfunction). In your postfunction compare ID stored in CF with issue ID. When they aren’t equal it’s a clone operation.

Hope it helps.

Regards
Josef