How to limit the number of open Issue of any Issuetype in a Jira Project
Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
Currently, In Jira, there is no limit on the number of issues that can be created within a particular project.
However, if there is a requirement where the admin needs to limit the number of issues that can be created within a project, then they can make use of Workflow validator and a third-party app ScriptRunner.
For example: Consider the requirement that the number of total Open epics in any system should not exceed the count of 100. Also, the users should not be allowed to create more issues if the open epics are already at the count 100.
Prerequisites
Solution
First, create a separate workflow for the Epic issue types and the other issues types can have a different workflow in the project. Refer to the below screenshot for reference:
For the workflow which is associated with the Epic issue type, go to the create issue transition and click on the validators option present on right side of the screen. Screenshot below:
Click on Add validator and then you can choose the option "Custom Script Validator [ScriptRunner]". The option will be visible if you ScriptRunner plugin installed.
Here we can write the validator code. Something as below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.bc.issue.search.SearchService import com.atlassian.jira.jql.parser.JqlQueryParser import com.atlassian.jira.issue.Issue import java.util.logging.Logger import com.opensymphony.workflow.InvalidInputException Logger logger = Logger.getLogger("") logger.info ("I am a test info log") def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser def jql= "project = abcde and issuetype = Epic and resolution = Unresolved" log.debug "JQL is: $jql" def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser) def searchService = ComponentAccessor.getComponent(SearchService) def query = jqlQueryParser.parseQuery(jql) def count=searchService.searchCount(user,query) if(count>=100){throw new InvalidInputException("The limit of open EPIC count is reached")}
Here for testing purposes, we have set the count to 100, one can set to the desired number. The important part is the JQL which test the open epic count. So, considering the project is ABCDE, we used the JQL: project = abcde and issuetype = Epic and resolution = Unresolved. The JQL could be different case by case basis as it may have different resolution statuses based on workflow used. So, please amend it based on the need/requirement.
Publish the changes. Once published, you will see the validator added.
Now if the user tries to create the issue once the limit is reached it will not allow the creation of epic and the below error could be seen.
Please note that this is a customisation and Atlassian would not be able to support it if it breaks in the future due to any reason. It could be due to plugin upgrade, Jira upgrade, or any other change. The script provided for validation is purely to demo the use case. This could be improved or an entirely different script could be used to validate. The onus of writing the script lies with the customer/user.
Was this helpful?