Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×Hi there,
Currently I am strugling with one thing in scriptRunner cloud jira, I am working on report, we want to check, how many components are covered by our tests.
The whole script is almost ready, but I can't get all issues with components field. Currently we have above 300 tests, but /rest/api/3/search limits results to only 100 items. How to change that?
def searchReq = get('/rest/api/3/search')
.queryString('jql', query)
.queryString('fields', 'components')
.asObject(Map)
assert searchReq.status == 200
Map searchResult = searchReq.body
int count = 0;
searchResult.issues.each { Map issue ->
count++
def components = issue.fields.components.name
}
println "${searchResult.total} iterations: ${count}"
So after running this simple script, I get 332 searchResult size but the loop goes only 50 times. Trying to change maxResults parameter allow me to increase iteration number up to 100 only.
Resolved it. So if you are new in this whole REST API like me, there is solution:
def searchReq = get('/rest/api/3/search')
.queryString('jql', query)
.queryString('fields', 'components')
.asObject(Map)
assert searchReq.status == 200
int searchResultTotal = (int) searchReq.body.total
int loopRunsCounter = searchResultTotal.intdiv(50)
int count = 0;
int componentsCount = 0
int startAt = 0
for (int i = 0; i <= loopRunsCounter; i++){
searchReq = get('/rest/api/3/search')
.queryString('jql', query)
.queryString('fields', 'components')
.queryString('startAt', startAt)
.asObject(Map)
Map searchResult = searchReq.body
startAt += 50
searchResult.issues.each { Map issue ->
count++
def components = issue.fields.components.name
for (Iterator<org.json.JSONObject> a = automatedComponents.iterator(); a.hasNext(); ){
def arr = a.next()
components.each{
if(arr.getString("name").equals(it)){
componentsCount++
a.remove()
}
}
}
}
}
So basically what you need to do, is:
a) determine how many pages of data will you get
b) loop through data, using "startAt" parameter, default maxResults is set to 50.
Unfortunatelly there is no method, to determine how many results will you get, that's why I am using search REST two times.
Thank you...your solution works great!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.