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

How do I stop users from creating issues with same value for a specific fix version

venkatesh_rajput March 3, 2023

I have a project where we manage release, now there are over 500 people using that project and sometimes people from the same team can raise issue with the same details.

I want to stop people from creating another issue which contains the same "Component" and "Region" only for a specific fix version. For every single component only 1 issue should be raised from a particular region I do not want two issues for a component with same region values.

Can I use the Create transition validator to restrict this and if yes then can someone please help me with the jql or groovy script.

1 answer

0 votes
Payne
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.
March 3, 2023 edited

Here is an example of running a JQL query within a Groovy script, so perhaps you can leverage this in a validator.

import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.search.SearchResults
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.web.bean.PagerFilter
String jqlSearch = "project = jadmin" //modify this to check for a component and region for a specific fix version
SearchService searchService = ComponentAccessor.getComponent(SearchService.class)
UserUtil userUtil = ComponentAccessor.getUserUtil()
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
IssueManager issueManager = ComponentAccessor.getIssueManager()
List<MutableIssue> issues = null
SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlSearch)
if (parseResult.isValid()) {
SearchResults searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
issues = searchResult.getResults().collect {issueManager.getIssueObject(it.id)}
//if issues count is > 0, then fail validation
} else {
log.error("Invalid JQL: " + jqlSearch);
}
venkatesh_rajput March 5, 2023

Hi @Payne 

So like there are more than 37 components and 4 regions, is there any way to write the code dynamically instead of mentioning all the components for all regions that too for a specific fix version

Payne
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.
March 6, 2023

I'm thinking you can define the jqlSearch variable to be something like this:

jqlSearch = "component = " + issue.component + " and region = " + issue.region + " and fixVersion = " + issue.fixVersion;

If that returns 1 or more issues, then fail validation.

I don't know offhand if region is a system field or a custom field; if custom, you will need to get it differently than issue.region. You may also need to wrap the data elements in quotes to handle embedded spaces, e.g. "component = " + "\"" + issue.component + "\""

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, team '25, conference, certifications, bootcamps, training experience, anaheim ca,

Want to make the most of Team ‘25?

Spend the day sharpening your skills in Atlassian Cloud Organization Admin or Jira Administration, then take the exam onsite. Already ready? Take one - or more - of 12 different certification exams while you’re in Anaheim at Team' 25.

Learn more
AUG Leaders

Upcoming Jira Events