Prevent duplicate issue creation by the Create issue post-function

This article describes how to avoid the creation of a second issue by the Create issue(s) post-function when the same transition is triggered a second time. For example, if you are using a Create Issue(s) post-function on the "Escalate" transition of a support workflow to create a separate "Escalation" ticket, you will want to avoid re-creating a new "Escalation" ticket if the Escalate transition is run a second time in the lifetime of the support request.

The idea is to use Conditional Execution to prevent the Create Issue(s) post-function from creating a new issue when an existing issue already created by that post-function can be found. There are multiple ways to achieve this, based on the specifics of your workflow.

Note that approaches 1 and 2 detailed below will work only when the current issue is linked to the newly created issue (using the "Link to new issue" option of the Create Issue(s) post-function). Approach 3 will work in all cases.

Approaches

  1. Check for the number of linked issues

    If you know that the current issue cannot have more than one issue linked to it through the link type configured on the "Link to new issue" option, then you can identify the existence of the issue similar to the one being created by checking for the number of issues linked to the current issue with the specific link type.

    Steps to follow:

    In the Conditional execution section of the post-function write the following script

    issue.getLinkedIssues("caused by").size() == 0

    The post-function will execute only when there are no issues linked to the current issue through the "caused by" link type.

  2. Check for the number of linked issues and specific characteristics of the created issue

    If you know that the current issue can have more than one issue linked to it through the link type configured on the "Link to new issue" option, but has unique characteristics, such as the same Summary as the current issue, then you can identify the existence of the issue similar to the one being created by finding an issue linked to the current issue with the specific link type and Summary same as the current issue.

    Steps to follow:

    In the Conditional execution section of the post-function write the following script:

    !(issue.getLinkedIssues("blocks").any{
    	it.summary == issue.summary
    })

    You can also use the searchIssues filter to find the issue having characteristics similar to the issue being created. 

    jqlSearch("project = Test and issue in linkedIssues(" + issue.key + ",blocks) and summary ~\"" + issue.summary + "\"",1) == null

    The post-function will execute only when there are no issues linked to the current issue through the "blocks" link type and with a Summary same as the current issue.

  3. Set an issue entity property and run the post-function based on its value

    Another approach is to set an issue entity property the first time the transition is run, and verify its value in the conditional execution of the post-function.

    Steps to follow:

    • In the Post-creation script of the Create issue post-function, add the following Groovy script:

      issue.setEntityProperty("New issue created", newIssueKey)
    • In the Conditional execution section of the Create issue post-function write the following script:

      issue.getEntityProperty("New issue created") == null

    The post-function will execute only when the current issue does not have an issue entity property with key "New issue created".