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

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


1 badge earned


Participate in fun challenges

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


Gift kudos to your peers

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


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!


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


0 votes
Joanna Choules
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.
Jun 01, 2020

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
AUG Leaders

Atlassian Community Events