Our new Appfire Documentation Space is now live!

Take a look here! If you have any questions please email support@appfire.com

Prevent duplicate issue creation by the Create issue(s) 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 | linkedIssues("caused by") | length == 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:

    {% set pass = false %}
    {%for i in issue | linkedIssues("caused by") %}
        {% if i.fields.summary == issue.fields.summary %}
            {% set pass = true %}
        {% endif %}
    {% endfor %}
    {{ pass }}

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

    {{("project = Test and issue in linkedIssues(" + issue.key+ " ,'caused by') and summary ~ " + 'issue.fields.summary') | searchIssues | length == 0 }}

    The post-function will execute only when there are no issues linked to the current issue through the "caused by" 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 Conditional execution section of the Create issue post-function write the following script:

      {{ issue | issueProperty ("New issue created") == null }}
    • Add the Set entity property post-function to the same transition.
    • Set the Current issue property, New issue created to Yes.
    • Add a 3 sec delay to this post-function.

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