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:
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()
SearchResults.getIssues() was changed a while ago to SearchResults.getResults()
You should change it accordingly. Please see the Java API here.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.