Get Current user's organization

Nessrine Hafi April 5, 2022

Hello, 

I've been trying to create a scripted field that returns the current user's organization ID. I tried with Rest Api but it doesn't work since i don't have my account ID. 

Is there anyway to get the organization id? Even an idea can help :) 

Have a nice day

1 answer

1 accepted

1 vote
Answer accepted
PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 11, 2022

A user could belong to more than one organization.

This script will give you all organization ids:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.servicedesk.api.organization.OrganizationService
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin

@WithPlugin("com.atlassian.servicedesk") sdPlugin //this allows the import of com.atlassian.servicedesk*
@PluginModule OrganizationService organizationService //this is the service we will use

def user = ComponentAccessor.userManager.getUserByName('qadnexteer')
def emptyQuery = organizationService.newOrganizationsQueryBuilder().build()

def response = organizationService.getOrganizations(user, emptyQuery)

response.results*.id 
Nessrine Hafi April 13, 2022

Hello Peter, 

It's working thank you. To get organization for specific project i just changed emptyQuery to :

def emptyQuery = organizationService.newOrganizationsQueryBuilder().serviceDeskId("ProjectID").build()
Diego Godoy Poce August 9, 2022

Hi,

This solution provide all the organizations for Service Desk or an specific project, but not for the specific user. The 'user' parameter is used only as an agent to get all the organizations, not his organizations.

I haven't found any way to get all organizations for an specific user directly, only using nested loops.

Regards.

Suggest an answer

Log in or Sign up to answer