Getting Reporter's Customer Organization Membership in ScriptRunner

Good morning.

I am trying to add automation that tests an issue reporter's membership in a customer organization.

I'm using the OrganizationService is com.atlassian.servicedesk.api.organization and the getById method, where I pass in the reporter's ApplicationUser object and specific customer organization IDs I wish to test against.


I'm getting a response of ' : 'You do not have permission to view this organization'


This response makes sense to me, the reporter I am passing in is not yet trusted. That is what I am trying to determine.


How can I, as a trusted automation/administrator, query the customer organization membership of the reporter?

1 answer

Hi James, 

The use of the OrganizationService.getById() seems ok, but I am not sure that gives you the result you want 

Quoting their javadocs (which make no sense)

* Checks whether the user is an agent or a member of the organization. True if
* - valid licensed,
* - is a member if the organization
* @param user the user who you want to check
* @param organizationId the ID of the organization you want retrieve.
* @return the organization.

But I believe the error you get it may has to do with permissions that the logged in user has (or in your case has not) and not the reporter

Apart from that could you please try the following script (check your logs for the debug messages or errors )?

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.servicedesk.api.organization.OrganizationService

def loggedInUser = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
def issue = ComponentAccessor.issueManager.getIssueByCurrentKey("ATG-1") //the issue to get the reporter from
def reporter = issue.reporter

def organisationService = ComponentAccessor.getOSGiComponentInstanceOfType(OrganizationService)
def organizationQuery = organisationService.newOrganizationsQueryBuilder().serviceDeskId(1).build()

def organizationsInProjectResult = organisationService.getOrganizations(loggedInUser, organizationQuery)
if (organizationsInProjectResult.isLeft()) {
log.error organizationsInProjectResult.left().get()

def organizationA = organizationsInProjectResult.right().get().results.find { == "OrgA"}
log.debug "Organization is $organizationA"

def usersInOrganizationQuery = organisationService.newUsersInOrganizationQuery().customerOrganization(organizationA).build()

def usersInOrganization = organisationService.getUsersInOrganization(loggedInUser, usersInOrganizationQuery)
if (usersInOrganization.isLeft()) {
log.error usersInOrganization.left().get()

def isUserInOrganization = usersInOrganization.right().get().results.find {it.key == reporter.key} ? true : false
log.debug "Is user in organizaion ? $isUserInOrganization"

Regards, Thanos

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Jan 15, 2019 in Statuspage

Introducing Statuspage Getting Started guides! First up: What is Statuspage?

Over the next several weeks we'll be sharing some of our Getting Started guides here in the community. Throughout this series of posts, we'd love to hear from customers and non-customers ab...

294 views 5 2
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you