Hello,
i will determine with my scriptrunner all Tickets there are the value of "Story Point" are changed and will print out this change.
Todo this, i have developed this code below but i get an error in line 21
groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.changehistory.DefaultChangeHistoryManager.getChangeItemsForField() is applicable for argument types: (com.atlassian.jira.issue.search.DocumentWithId, String) values: [com.atlassian.jira.issue.search.DocumentWithId@4e6bb95e, Story Points] Possible solutions: getChangeItemsForField(com.atlassian.jira.issue.Issue, java.lang.String), getChangeItemsForField(com.atlassian.jira.issue.Issue, java.lang.String, java.util.Date) at Script32$_run_closure1.doCall(Script32.groovy:21) at Script32.run(Script32.groovy:19)
i don't understand what is false?
Please can you help me?
import java.lang.String
import com.atlassian.jira.issue.search.SearchQuery
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.builder.JqlQueryBuilder
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.query.Query
// Initialisierung
SearchProvider searchProvider = ComponentAccessor.getComponent(SearchProvider.class)
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
//Query query = queryBuilder.where().addStringCondition(jqlQuery).buildQuery()
PagerFilter pagerFilter = PagerFilter.getUnlimitedFilter()
JqlQueryBuilder queryBuilder = JqlQueryBuilder.newBuilder()
Query query = queryBuilder.where().project("Core Data Management Services").buildQuery()
log.warn("${query.toString()}")
SearchQuery searchQuery = SearchQuery.create(query,user)
def searchResults = searchProvider.search(searchQuery, pagerFilter)
searchResults.getResults().each { issue ->
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def changeItems = changeHistoryManager.getChangeItemsForField(issue,"Story Points")
changeItems.each { changeItem ->
if (changeItem.field == "Story Points") {
println "Ticket-ID: ${issue.key}, Alter Wert: ${changeItem.fromString}, Neuer Wert: ${changeItem.toString}
}
}
}
THe searchProvidor compoent returns a "documentWithId" object from the lucene search index.
It will be up to you to convert that to a class that the changeHistoryManager can handle.
Somethinkg like this:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.issue.search.SearchQuery
import com.atlassian.jira.jql.builder.JqlQueryBuilder
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.query.Query
// Initialisierung
SearchProvider searchProvider = ComponentAccessor.getComponent(SearchProvider.class)
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
//Query query = queryBuilder.where().addStringCondition(jqlQuery).buildQuery()
PagerFilter pagerFilter = PagerFilter.getUnlimitedFilter()
JqlQueryBuilder queryBuilder = JqlQueryBuilder.newBuilder()
Query query = queryBuilder.where().project("Core Data Management Services").buildQuery()
log.warn("${query.toString()}")
SearchQuery searchQuery = SearchQuery.create(query, user)
def searchResults = searchProvider.search(searchQuery, pagerFilter)
searchResults.getResults().each { indexDoc ->
def issue = ComponentAccessor.issueManager.getIssueObject(indexDoc.docId)
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def changeItems = changeHistoryManager.getChangeItemsForField(issue, "Story Points")
changeItems.each { changeItem ->
if (changeItem.field == "Story Points") {
println "Ticket-ID: ${issue.key}, Alter Wert: ${changeItem.fromString}, Neuer Wert: ${changeItem.toString}"
}
}
}
But in truth, the searchProvider is the lowest level API for this, it might be preferable to leverage either the "SearchService". One big drawback of the search provider is that it doesn't respect permissions. You might retrieve issues that should not be accessible to the user.
SearchService Implementation
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.web.bean.PagerFilter
// Initialisierung
SearchService searchService = ComponentAccessor.getComponent(SearchService)
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
PagerFilter pagerFilter = PagerFilter.getUnlimitedFilter()
def parseResult = searchService.parseQuery(user, "project='Core Data Management Services'")
assert parseResult.isValid()
searchService.search(user, parseResult.query, pagerFilter).results.each { issue ->
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def changeItems = changeHistoryManager.getChangeItemsForField(issue, "Story Points")
changeItems.each { changeItem ->
if (changeItem.field == "Story Points") {
println "Ticket-ID: ${issue.key}, Alter Wert: ${changeItem.fromString}, Neuer Wert: ${changeItem.toString}"
}
}
}
Or even better, use the HAPI interface.
import com.adaptavist.hapi.jira.issues.Issues
import com.atlassian.jira.component.ComponentAccessor
Issues.search("project='Core Data Management Services'").each { issue ->
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def changeItems = changeHistoryManager.getChangeItemsForField(issue, "Story Points")
changeItems.each { changeItem ->
if (changeItem.field == "Story Points") {
println "Ticket-ID: ${issue.key}, Alter Wert: ${changeItem.fromString}, Neuer Wert: ${changeItem.toString}"
}
}
}
The exception tells you the problem exactly, all you need to do is either sit back and think about it or google it.
Lately it seems to me people are posting java/groovy related problems which are not really supposed to be part of this forum.
On a less truthful and more pretentious helpful note, you don't want to use whatever this SearchProvider is, you want to use SearchService (https://docs.atlassian.com/software/jira/docs/api/9.4.11/com/atlassian/jira/bc/issue/search/SearchService.html) because that actually returns the expected data type that you can pass to ChangeHistoryManager.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Kindness doesn't seem to be your forte, does it? Aside from that, Groovy is a component of the Jira plugin ScriptRunner and thus is indeed part of the forum.
It would be nice to offer help instead of complaining.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Support for Groovy scripting has long history in the atlassian community forums.
There used to be a dedicated group for that, but since last year's restructuring, it's less obvious. Maybe those questions would better be served in the App Central group, I don't think that really matters.
If you are not prepared to offer help on those topics, you can just skip the question.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.