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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Scriptrunner syntax errors in Issue Organizations member emails script

Hi, Im getting syntax errors from the below script when I try to read email addresses from the Issue Organizations. It's returning the correct output in the log and the logic seems to be working. But for some reason it has syntax errors. Can someone please help? Thanks.

 

import com.adaptavist.hapi.jira.users.Users
import com.atlassian.servicedesk.api.ServiceDeskManager
import com.atlassian.servicedesk.api.organization.OrganizationService
import com.atlassian.servicedesk.api.organization.OrganizationsQuery
import com.atlassian.servicedesk.api.util.paging.SimplePagedRequest
import com.atlassian.servicedesk.internal.feature.organization.model.CustomerOrganizationImpl
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin


@WithPlugin("com.atlassian.servicedesk")
 
@PluginModule
ServiceDeskManager serviceDeskManager
 
@PluginModule
OrganizationService organizationService

def issuesForOrganizations = Issues.getByKey('XXX-1010')
 
def customerOrg = issuesForOrganizations.getCustomFieldValue('Organizations') as List<CustomerOrganizationImpl>
 
def loggedInUser = Users.loggedInUser
def serviceDeskProject = serviceDeskManager.getServiceDeskForProject(issuesForOrganizations.projectObject)
 
def serviceDeskId = serviceDeskProject.id as Integer

// get the available organizations for that project
Boolean NextPageCheck = true
Integer StartRequest = 0
def organizationsResults = []

do {
    OrganizationsQuery organizationsQuery = organizationService.newOrganizationsQueryBuilder().pagedRequest(new SimplePagedRequest(StartRequest,50)).build()
    def result = organizationService.getOrganizations(loggedInUser, organizationsQuery)
    organizationsResults.addAll(result?.toList())
    NextPageCheck = result.hasNextPage()
    StartRequest = StartRequest + result.size()
    } while (NextPageCheck)

def usersInOrganizations = new StringBuilder()

 if (organizationsResults != null) {organizationsResults.each { organization ->
 customerOrg['name'].each {
 if (it == organization.name ) {
 def usersInOrganizationQuery = organizationService
.newUsersInOrganizationQuery()
.customerOrganization(organization)
.pagedRequest(new SimplePagedRequest(0, 50))
.build()
usersInOrganizations.append(organizationService.getUsersInOrganization(loggedInUser, usersInOrganizationQuery).results.collect {it.emailAddress}.join(',')).append(',')
}
}
}}
log.warn "====>>> ${usersInOrganizations.toString().replaceFirst('.$','') }"

Script Error.png

2 answers

1 accepted

0 votes
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Oct 03, 2023

It appears that the code editor/code checker is losing track of what "organizationResults" is or should be. So it can't verify that "name" is valid. Then all the rest follows.

If static type-checking errors bother you (they are a tool for the developer, not a guarantee that your code is bad), you can force the matter by declaring your organization explicitly.

Something like:

List<CustomerOrganization> organizationsResults = []

Also, you might want to adjust your variable names. Initial capitals are reserved for class names. That's why the editor highlights  NextPageCheck and StartRequest in green.
By convention, those should start with a lowercase.

Thanks @Peter-Dave Sheehan

Your solution worked great!

Suggest an answer

Log in or Sign up to answer