Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Duplicate query results by using Organization groovy API


I'm using Scriptrunner in our Jira Service Management Datacenter setup to manage Organizations.

When I run the script (see below) the Organization query returns duplicates i.e. the same Organization is returned on different pages in response' pagedresult. When I run the script multiple times consequently, then usually first couple of times I do get duplicates, but then Jira returns duplicate-less response.

What could be the root cause here?

Kind Regards,


import static*

import org.apache.log4j.Level
import org.apache.log4j.Logger

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.servicedesk.api.organization.CustomerOrganization
import com.atlassian.servicedesk.api.organization.OrganizationService
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.servicedesk.api.util.paging.SimplePagedRequest
import com.atlassian.servicedesk.api.util.paging.LimitedPagedRequestImpl


// set up a logger
def lgr = Logger.getLogger("GettingOrgs")

def isLastPageReached = false
def startIndex = 0
ArrayList jsdOrgsList = []
def infiniteLoopPrevention = 10000
def duplicatesCounter = 0

def adminUser = ComponentAccessor.userManager.getUserByKey('JIRAUSER10300')
def organisationService = ComponentAccessor.getOSGiComponentInstanceOfType(OrganizationService)

while (!isLastPageReached && (infiniteLoopPrevention-- >0)) {

def organizationQuery = organisationService
.pagedRequest(SimplePagedRequest.paged(startIndex, 6000))

def pagedRes = organisationService.getOrganizations(adminUser, organizationQuery)

pagedRes.getResults().each { pagedResElement->

if (jsdOrgsList.find{it.jsdId ==} == null) {

} else {

startIndex +=50
isLastPageReached = !pagedRes.hasNextPage()

lgr.debug("duplicatesCounter = ${duplicatesCounter}")
lgr.debug("Unique orgs count on all pages = ${jsdOrgsList.size()}")
def sumtotal = duplicatesCounter + jsdOrgsList.size()
lgr.debug("Sum of unique count and duplicates = ${sumtotal}")

1 answer

Hell Andrey,

I think I see the error:

.pagedRequest(SimplePagedRequest.paged(startIndex, 6000))

You ask the api to retrieve 6000 rows, starting from startIndex, but the limit for each paged request is 50, so the api only retrieves 50.

Try changing it it to:

.pagedRequest(SimplePagedRequest.paged(startIndex, 50))


Let me know if this helped!



Hello Jeroen,

thank you for your response. I have tested the query with different values like 50, 6000, 30... The result is always the same: duplicates sometimes occur.

So far, I've found an workaround: I've put the query into a loop with a threshold on iterations count. After a couple of iterations, jira returns the Orgs without duplicates. It means, the same code returns for the same data different results. This lets us assume, that we have some caching / nodes synchronization issue.



Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira Service Management

Submit your Jira Service Management use case and win!

Hi everyone - in case you haven’t heard, we’re hosting the show of the century on November 10th: High Velocity: ITSM World Tour.     This virtual, concert-themed experience...

317 views 1 11
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you