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

Add specific organization via ScriptRunner ( i need to check if customer is in a specific group)

Hello guys,

I search every where and check all discussion but I'm not able to find the answer/suggestion I need. I realize a big script running on listener and triggered by Issue creation on JSD 4.8.0 on Jira Core 8.8.0 and Adaptavist ScriptRunner for JIRA version 6.0.2-p5.

the script is checking if the reporter is present in a specific group and needs to add few "RequestPartecipants" ( the area manager in charge for that area) and add few Organization ( the local re-sellers). I don't find the way to add specific organization I would like to.

Here you can find a reduced version of the script, where in the INDIA case, I would like to add an organization ( customer organization is added by default ). in the same place you can find few rows of commented code that I tried but they are wrong. Is there anyone can provide me suggestion?

thanks in advance


import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.onresolve.scriptrunner.db.DatabaseUtil
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser
import java.util.ArrayList
import groovy.transform.BaseScript
import com.atlassian.servicedesk.api.ServiceDesk
import com.atlassian.servicedesk.api.ServiceDeskManager
import com.atlassian.servicedesk.api.organization.CustomerOrganization
import com.atlassian.servicedesk.api.organization.OrganizationService
import com.atlassian.servicedesk.api.organization.OrganizationsQuery
import com.atlassian.servicedesk.api.util.paging.LimitedPagedRequest
import com.atlassian.servicedesk.api.util.paging.LimitedPagedRequestImpl
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.crowd.embedded.api.Group
import groovy.transform.Field

ServiceDeskManager serviceDeskManager
OrganizationService organizationService

// Enable debugger

import org.apache.log4j.Logger
import org.apache.log4j.Level
def _log = Logger.getLogger("com.acme.CreateSubtask")

// end debug

def issue = event.issue
issue = issue as MutableIssue
def issueManager = ComponentAccessor.issueManager
def currentReporter = issue.reporter"Begin : Current reporter = " +
def customFieldManager = ComponentAccessor.getCustomFieldManager()

CustomField organizationObj = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName("Organizations").first() // Organizations custom field
def organizationCFValue = issue.getCustomFieldValue(organizationObj)"Begin : Organizations custom field:" + organizationCFValue)

CustomField requestPartecipantsObj = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName("Request participants").first() // Request Partecipant
def partecipatsCFValue = issue.getCustomFieldValue(requestPartecipantsObj)

def userManager = ComponentAccessor.getUserManager()"Begin : Request Partecipant custom field:" + partecipatsCFValue)"Begin : Begin : Script called")

GroupPickerSearchService groupSearch = ComponentAccessor.getComponent(GroupPickerSearchService.class)
List<Group> groupList = groupSearch.findGroups("")
ArrayList<ApplicationUser> userList = new ArrayList<ApplicationUser>()

// get all the organizations configured for that project
List<CustomerOrganization> organizationsToAdd
ArrayList<CustomerOrganization> agencyList = new ArrayList<CustomerOrganization>()
def organisationService = ComponentAccessor.getOSGiComponentInstanceOfType(OrganizationService)

ServiceDesk serviceDeskProject
def serviceDeskId = serviceDeskProject?.id as Integer

// get the available organizations for that project
def organizationsQuery = organizationService.newOrganizationsQueryBuilder().serviceDeskId(serviceDeskId).build()

def familyNameDbValue
def getUsersAsArray = []
def users = []
def biUser = ""

biUser ="businnessUnit"

// Set Request Partecipant, BI, AM and Agency
for (Group group : groupList){"GroupName Found:" + group.getName());
if(ComponentAccessor.groupManager.getUserNamesInGroup(group.getName()).contains({"I found User: " + + " in GroupName: " + group.getName());
switch(group.getName()) {
// aggiungi partecipanti
getUsersAsArray = {
users = ["giuseppe", biUser]"Users : "+ users);
def user = userManager.getUserByName(it)"Area Manager: Giuseppe");
return userList
try {"CASE - 6 : 1 = " + getUsersAsArray);
ArrayList<ApplicationUser> applicationUsers = getUsersAsArray()"CASE - 6 : = " + applicationUsers);
requestPartecipantsObj.updateValue(null, issue, new ModifiedValue(partecipatsCFValue, applicationUsers), new DefaultIssueChangeHolder());
} catch (ignored) {"CASE - 6 : none");

if( group.getName() == "INDIA"){"Organization for this Area: LOCAL AGENCY");
def agencies = ["LOCAL AGENCY"]
def getAgentsAsArray = {
// this piece of code is not correct and not working
//def organisationService = ComponentAccessor.getOSGiComponentInstanceOfType(OrganizationService)
//def organizationQuery = organisationService.newOrganizationsQueryBuilder().serviceDeskId(1).build()
//def agency = organisationService.getOrganizations(currentReported, organizationQuery)

return agencyList
// unpdate here the custom field
default:"CASE - DEFAULT");





2 answers

Hi Johanna,


thanks for this suggestion but I think I was searching for another answer. Actually I know how to add customer organization to the ticket but what I do not know is how to add another organization where this customer is not involved. So, in my previous post the code is commented.

so, assuming this PSEUDO code:

IF ( Ivan is in Group Name "A" ) Then

add Organization B 



please note that Ivan is not in Organization B


many thanks


Hi Ivan,

What specifically seems to be wrong with the code you've written? Does it throw any errors?

One thing I would note is that the organizations query builder requires you to specify a PagedRequest as well as the ID of a service desk:

import com.atlassian.servicedesk.api.util.paging.SimplePagedRequest


def organizationQuery = organisationService
.pagedRequest(SimplePagedRequest.paged(0, 100))

 (The first argument to paged is the starting index, and the second argument is the limit: I've chosen 0 and 100 here but you may need to change this to suit your own use case.)


Joanna Choules, Adaptavist Product Support

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

394 views 3 17
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