Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Prevent issue opening if same request type has been created less than X days ago

Luca Lo Casto February 9, 2022

Good morning,

I'm trying to prevent an issue to be open if the same account created an issue with the same request type less than 2 months ago.

I was thinking to use a Script Runner Validators, i'm searching any code about it with no success.

Currently i can't find any alternative or workaround.

Does anybody smarter than me helps me? 

Thanks,
Luca

2 answers

0 votes
Tuncay Senturk _Snapbytes_
Community Champion
February 10, 2022

Hi @Luca Lo Casto 

It is not 100% clear but as far as I understand your JQL should be like

 

String projectName = issue.getProjectObject().getName()
String summary = issue.getSummary()
String queryJql = """project = "$projectName" AND summary ~ "$summary" AND reporter = currentUser() AND updatedDate >= startOfDay(-60d)"""

 

I hope this sheds some light.

0 votes
Luca Lo Casto February 9, 2022

Hello,

This is a part of the script


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.web.bean.PagerFilter
import com.opensymphony.workflow.InvalidInputException;

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

// Query per fare la ricerca JQL
String queryJql = 'summary ~ "Terminale*" AND reporter = currentUser() AND updatedDate >= startofDay(-60d)'

def query = jqlQueryParser.parseQuery(queryJql)

def search = searchService.search(user, query, PagerFilter.getUnlimitedFilter())

if(search.results.size() >= 1)
throw new InvalidInputException("E' stata aperta una richiesta meno di 60 giorni fa.")


It throws an exception when i try to create another ticket within the same project (the project is called "Terminale" too), instead i need it to throw an exception when i try to create a ticket with the same "Request name".

Any suggest?

Thanks.


Suggest an answer

Log in or Sign up to answer