Duplicate values custom field

Carmen Bullock February 29, 2024

I am trying to write a script that will run on issue creation that will do the following for a specific field - we will call it Field 1, which is a Text Field, Single Line:

  • read the data value being stored in Field 1
  • query the project to see if that value already exists in Field 1
  • reject/prevent creation of the issue.
  • generate an error message to notify the issue creator that the provided data value already exists in the project.

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.fields.CustomField
import com.atlassian.jira.issue.search.SearchResults
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.query.Query
import com.opensymphony.workflow.InvalidInputException

def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cveField = customFieldManager.getCustomFieldObject("customfield_20300")

def cveFieldValue = issue.getCustomFieldValue(cveField)
String jql = "\"CVE ID\" ~ ${cveFieldValue}"
List<MutableIssue> jqlIssues = getIssuesFromJQL(jql)

if (jqlIssues) {
throw new InvalidInputException("CVE ID already exists in issues: ${jqlIssues}")
return true

List<MutableIssue> getIssuesFromJQL(String jqlQuery) {
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
IssueManager issueManager = ComponentAccessor.getIssueManager()
JqlQueryParser jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class)
SearchService searchService = ComponentAccessor.getComponent(SearchService.class)
Query query = jqlQueryParser.parseQuery(jqlQuery)
SearchResults searchResults = searchService.search(user, query, PagerFilter.getUnlimitedFilter())
List<MutableIssue> mutableIssueList = searchResults.getIssues().collect { issue -> issueManager.getIssueObject(issue.getId()) }
return mutableIssueList


I am getting this error:

No signature of method: com.atlassian.jira.issue.search.SearchResults.getIssues() is applicable for argument types: () values: [] Possible solutions: getPages(), getResults(), getClass()

1 answer

0 votes
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 3, 2024

Hi @Carmen Bullock 

SearchResults.getIssues() was changed a while ago to SearchResults.getResults() 

You should change it accordingly. Please see the Java API here.

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events