Hi,
I'm trying to find a way to get a string of email addresses from Organizations (multiple) assigned to an issue. Ideally, I want to run this script through a custom listener and produce a string of email addresses separated by a comma.
Can anyone help me with building the script using the latest HAPI interface?
Regards
Roshan
Below is an example working code for your requirement:-
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.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 issue = event.issue
def loggedInUser = Users.loggedInUser
def customerOrg = issue.getCustomFieldValue('Organizations') as List<CustomerOrganizationImpl>
def project = issue.projectObject
def serviceDeskProject = serviceDeskManager.getServiceDeskForProject(project)
def serviceDeskId = serviceDeskProject.id as Integer
def organizationsQuery = organizationService.newOrganizationsQueryBuilder().serviceDeskId(serviceDeskId).build()
def result = organizationService.getOrganizations(loggedInUser, organizationsQuery)
def usersInOrganizations = new StringBuilder()
result.results.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.displayName}.join(',')).append(',')
}
}
}
log.warn "====>>> ${usersInOrganizations.toString().replaceFirst('.$','') }"
Please note that the sample code above is not 100% exact to your environment. Hence, you will need to make the required modifications.
Below is a screenshot of the Listener configuration:-
I hope this helps to answer your question. :-)
Thank you and Kind regards,
Ram
Many thanks @Ram Kumar Aravindakshan _Adaptavist_
This is exactly what I was after. Thank you again!!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ram Kumar Aravindakshan _Adaptavist_
Can you please adjust the script to capture all available Organizations instead of the first 50? I can't figure out how to include customers from other pages on the Page Request.
Thanks in advance
Roshan
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.