Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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

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.
Mar 03, 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);
}

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.
Mar 06, 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
AUG Leaders

Atlassian Community Events