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.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.