Having a way to sync groups of users to specific Service Desk Organizations would be a lifesaver. Any help or advice?
Hi Eric,
So, without knowing any details, I am thinking of a Service that will run every <time> and will do the sync, or even a script that you will tun it from the script console.
The script that will perform the sync will look like
import com.atlassian.jira.component.ComponentAccessor
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.util.paging.SimplePagedRequest
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
@WithPlugin("com.atlassian.servicedesk")
def serviceDeskManager = ComponentAccessor.getOSGiComponentInstanceOfType(ServiceDeskManager)
def organisationService = ComponentAccessor.getOSGiComponentInstanceOfType(OrganizationService)
def adminUser = ComponentAccessor.userManager.getUserByKey("admin")
def project = ComponentAccessor.projectManager.getProjectByCurrentKey("SDP")
def serviceDeskProjectResult = serviceDeskManager.getServiceDeskForProject(project)
if (serviceDeskProjectResult.isLeft()) {
log.debug serviceDeskProjectResult.left().get()
return
}
def serviceDeskId = serviceDeskProjectResult.right().get().id
def organizationQuery = organisationService.newOrganizationsQueryBuilder()
.serviceDeskId(serviceDeskId)
.pagedRequest(new SimplePagedRequest(0, 50))
.build()
def organizationsResult = organisationService.getOrganizations(adminUser, organizationQuery)
if (organizationsResult.isLeft()) {
log.debug organizationsResult.left().get()
return
}
def organization = organizationsResult.right().get().results.findByName("Jira Users")
syncGroupUsersToOrganization(organization, "jira-users")
void syncGroupUsersToOrganization(CustomerOrganization organization, String groupName ) {
def organisationService = ComponentAccessor.getOSGiComponentInstanceOfType(OrganizationService)
def adminUser = ComponentAccessor.userManager.getUserByKey("admin")
def usersInOrganization = organisationService
.newUsersInOrganizationQuery()
.customerOrganization(organization)
.pagedRequest(new SimplePagedRequest(0, 50))
.build()
def currentUsersInOrganizationResult = organisationService.getUsersInOrganization(adminUser, usersInOrganization)
if (currentUsersInOrganizationResult.isLeft()) {
currentUsersInOrganizationResult.left().get()
return
}
def currentUsersInOrganization = currentUsersInOrganizationResult.right().get().results
def usersInGroup = ComponentAccessor.groupManager.getUsersInGroup(groupName)
def usersToRemove = currentUsersInOrganization - usersInGroup
def usersToAdd = usersInGroup - currentUsersInOrganization
def usersToAddInOrganizationUpdateParameters = organisationService.newUsersOrganizationUpdateParametersBuilder().organization(organization).users(usersToAdd?.toSet()).build()
def usersToRemoveFromOrganizationUpdateParameters = organisationService.newUsersOrganizationUpdateParametersBuilder().organization(organization).users(usersToRemove?.toSet()).build()
organisationService.addUsersToOrganization(adminUser, usersToAddInOrganizationUpdateParameters) // add users that are in the group and not in the organization
organisationService.removeUsersFromOrganization(adminUser, usersToRemoveFromOrganizationUpdateParameters) //remove users that are no longer in that group
}
Keep in mind that this is not properly tested, and given the fact that people in an organisation may have access to issues with confidential information, you will have to make sure that the expected users are in the expected organisations.
One more thing, to keep in mind is that every project has its own organisations.
Please let me know if you have any questions.
Regards, Thanos
Thank you so much for helping. Copying what you have (changing just the username and project) I am getting the following error:
2018-03-29 19:59:03,698 WARN [common.UserScriptEndpoint]: Script console script failed: groovy.lang.MissingMethodException: No signature of method: com.atlassian.servicedesk.internal.feature.organization.api.OrganizationsQueryImpl$Builder.serviceDeskId() is applicable for argument types: (com.atlassian.servicedesk.internal.feature.servicedesk.ServiceDeskImpl) values: [ServiceDeskImpl{serviceDeskId=1, projectId=10001, projectName=Release Management, accessConfig=AccessConfig{publicSignUp=false, openAccess=true}, createdByUserKey=some(egcolli), createdDate=some(2018-03-20 17:33:01.671), createdWithEmptyProject=some(true), createdAtVersion=some(3.11.1-REL-0014), legacyCommentTransitionDisabled=true}] Possible solutions: serviceDeskId(java.lang.Integer) at Script57.run(Script57.groovy:24)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Eric,
can I ask you in which version of Service Desk you are ?
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.
Hey Eric,
That is weird I just ran the script with the same versions as you and It works fine.
I also ran it against service desk version 3.11.1
Can you please make sure that you copied the script correctly ? Especially the lines
def serviceDeskId = serviceDeskProjectResult.right().get().id
def organizationQuery = organisationService.newOrganizationsQueryBuilder()
.serviceDeskId(serviceDeskId)
.pagedRequest(new SimplePagedRequest(0, 50))
.build()
Also if you pasted this into the script console and you get some error indications, is it safe to ignore them probably are because of the static type checking. Just run it and then check the application logs if any "real"
Thanks, Thanos
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.
Hello @Thanos Batagiannis [Adaptavist],
using the code above I get the follow error. Would you please give me a hint what I am doing wrong?
JIRA Service Desk 3.11.2
JIRA Software 7.8.2
Kind regards
Baris
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Thanos Batagiannis [Adaptavist]
The script above works great for groups/orgs less than 50 people.
Is there a way to modify the pageRequest lines to support over 50 people, like upto 1000?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
we used this script successfully until we updated to Jira 8.2.0 (SD: 4.2.0).
import com.atlassian.jira.component.ComponentAccessor
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.util.paging.SimplePagedRequest
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
@WithPlugin("com.atlassian.servicedesk")
def serviceDeskManager = ComponentAccessor.getOSGiComponentInstanceOfType(ServiceDeskManager)
def organisationService = ComponentAccessor.getOSGiComponentInstanceOfType(OrganizationService)
def adminUser = ComponentAccessor.userManager.getUserByKey("User")
def project = ComponentAccessor.projectManager.getProjectByCurrentKey("KEY")
def serviceDeskProjectResult = serviceDeskManager.getServiceDeskForProject(project)
if (serviceDeskProjectResult.isLeft()) {
log.debug serviceDeskProjectResult.left().get()
return
}
def serviceDeskId = serviceDeskProjectResult.right().get().id
def organizationQuery = organisationService.newOrganizationsQueryBuilder()
.serviceDeskId(serviceDeskId)
.pagedRequest(new SimplePagedRequest(0, 50))
.build()
def organizationsResult = organisationService.getOrganizations(adminUser, organizationQuery)
if (organizationsResult.isLeft()) {
log.debug organizationsResult.left().get()
return
}
def organizationAll = organizationsResult.right().get().results.findByName("Organization_Z")
syncGroupUsersToOrganization(organizationAll, "Group_Z")
def organizationH41 = organizationsResult.right().get().results.findByName("Organization_A")
syncGroupUsersToOrganization(organizationH41, "Group_A")
def organizationT38 = organizationsResult.right().get().results.findByName("Organization_B")
syncGroupUsersToOrganization(organizationT38, "Group_B")
def organizationL254 = organizationsResult.right().get().results.findByName("Organization_C")
syncGroupUsersToOrganization(organizationL254, "Group_C")
void syncGroupUsersToOrganization(CustomerOrganization organization, String groupName ) {
def organisationService = ComponentAccessor.getOSGiComponentInstanceOfType(OrganizationService)
def adminUser = ComponentAccessor.userManager.getUserByKey("User")
def usersInOrganization = organisationService
.newUsersInOrganizationQuery()
.customerOrganization(organization)
.pagedRequest(new SimplePagedRequest(0, 50))
.build()
def currentUsersInOrganizationResult = organisationService.getUsersInOrganization(adminUser, usersInOrganization)
if (currentUsersInOrganizationResult.isLeft()) {
currentUsersInOrganizationResult.left().get()
return
}
def currentUsersInOrganization = currentUsersInOrganizationResult.right().get().results
def usersInGroup = ComponentAccessor.groupManager.getUsersInGroup(groupName)
def usersToRemove = currentUsersInOrganization - usersInGroup
def usersToAdd = usersInGroup - currentUsersInOrganization
def usersToAddInOrganizationUpdateParameters = organisationService.newUsersOrganizationUpdateParametersBuilder().organization(organization).users(usersToAdd?.toSet()).build()
def usersToRemoveFromOrganizationUpdateParameters = organisationService.newUsersOrganizationUpdateParametersBuilder().organization(organization).users(usersToRemove?.toSet()).build()
organisationService.addUsersToOrganization(adminUser, usersToAddInOrganizationUpdateParameters) // add users that are in the group and not in the organization
organisationService.removeUsersFromOrganization(adminUser, usersToRemoveFromOrganizationUpdateParameters) //remove users that are no longer in that group
}
Now we are getting this error:
groovy.lang.MissingMethodException: No signature of method: com.atlassian.servicedesk.internal.feature.servicedesk.ServiceDeskImpl.isLeft() is applicable for argument types: () values: [] Possible solutions: inspect(), inject(groovy.lang.Closure), inject(java.lang.Object, groovy.lang.Closure), sleep(long), sleep(long, groovy.lang.Closure), split(groovy.lang.Closure) at Script35.run(Script35.groovy:17)
No signature of method: com.atlassian.servicedesk.internal.feature.servicedesk.ServiceDeskImpl.isLeft()
Does someone have an Idea how solve this issue?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
We upgraded to JSD 4.5.4 / Jira Core 8.5.4 and get same error message.
Anyone have an updated version that works on Jira 8.x / JSD 4.x?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you still have this error. See my code below can help you
This is my solution below. Also if you pasted this into the script console and get some error indications, is it safe to ignore them probably are because of the static type checking. Just run it and then check the application logs if any "real"
import
com.atlassian.jira.component.ComponentAccessor
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.util.paging.SimplePagedRequest
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
@WithPlugin("com.atlassian.servicedesk")
def serviceDeskManager = ComponentAccessor.getOSGiComponentInstanceOfType(ServiceDeskManager)
def organisationService = ComponentAccessor.getOSGiComponentInstanceOfType(OrganizationService)
//get your Project Key and your User Key
//my project key=IP and user=admin
def adminUser = ComponentAccessor.userManager.getUserByKey("admin")
def project = ComponentAccessor.projectManager.getProjectByCurrentKey("IP")
def serviceDeskProjectResult = serviceDeskManager.getServiceDeskForProject(project)if
(serviceDeskProjectResult.isLeft()) {
log.debug serviceDeskProjectResult.left().
get
()
return
}
//note: service desk id != project iddef
serviceDeskId = serviceDeskProjectResult.right().
get
().id
def
organizationQuery = organisationService.newOrganizationsQueryBuilder()
.serviceDeskId(serviceDeskId).pagedRequest(
new
SimplePagedRequest(
0
,
50
))
.build()def
organizationsResult = organisationService.getOrganizations(adminUser, organizationQuery)
if
(organizationsResult.isLeft()) {
log.debug organizationsResult.left().
get
()
return
}
//put your organization ex:VAAdef
organization = organizationsResult.right().
get
().results.findByName(
"VAA"
)
//sync your group ex:HR Dep’t to organization VAA
syncGroupUsersToOrganization(organization, "HR Dep’t")
void syncGroupUsersToOrganization(CustomerOrganization organization, String groupName ) {def
organisationService = ComponentAccessor.getOSGiComponentInstanceOfType(OrganizationService)
def
adminUser = ComponentAccessor.userManager.getUserByKey(
"admin"
)
def
usersInOrganization = organisationService
.newUsersInOrganizationQuery()
.customerOrganization(organization)
.pagedRequest(
new
SimplePagedRequest(
0
,
50
))
.build()
def
currentUsersInOrganizationResult = organisationService.getUsersInOrganization(adminUser, usersInOrganization)
if (currentUsersInOrganizationResult.isLeft()) {
currentUsersInOrganizationResult.left().get()
return
}
def currentUsersInOrganization = currentUsersInOrganizationResult.right().get().results
def usersInGroup = ComponentAccessor.groupManager.getUsersInGroup(groupName)
def usersToRemove = currentUsersInOrganization - usersInGroup
def usersToAdd = usersInGroup - currentUsersInOrganization
def usersToAddInOrganizationUpdateParameters = organisationService.newUsersOrganizationUpdateParametersBuilder().organization(organization).users(usersToAdd?.toSet()).build()
def usersToRemoveFromOrganizationUpdateParameters = organisationService.newUsersOrganizationUpdateParametersBuilder().organization(organization).users(usersToRemove?.toSet()).build()
organisationService.addUsersToOrganization(adminUser, usersToAddInOrganizationUpdateParameters) // add users that are in the group and not in the organization
organisationService.removeUsersFromOrganization(adminUser, usersToRemoveFromOrganizationUpdateParameters) //remove users that are no longer in that group
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That's right, syncing Jira user groups with Jira Service Desk Organizations has not been available out-of-the-box, and there's been no workaround other than scripting as provided by @Thanos Batagiannis [Adaptavist]... until we at Deviniti added Organizations and Groups Sync as an admin feature to Extension for Jira Service Desk. Now it's just a simple configuration with two possibilities: you either create new Organizations straight from the respective user groups, or assign them to existing ones (multiple groups to one Org as well). Both options are synced by a single CRON expression. Learn more by reading this article if you're interested, and feel free to ask any questions.
Cheers,
Dzmitry
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi ,
Will you any time add a function to delete the organizations from the project also?
Cheers
Johan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Johan,
We have no plans to develop this functionality. But please submit a request via our customer portal. We collect any feedback from our users, so maybe in the future we'll add this option.
Kate
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.
I am getting below error on this code.
def serviceDeskProjectResult = serviceDeskManager.getServiceDeskForProject(project)
if (serviceDeskProjectResult.isLeft()) {
log.debug serviceDeskProjectResult.left().get()
return
}
//note: service desk id != project id
Anyone have updated code then please share.
I am using Jira Software - 8.5.0 and JIRA Service Desk Application - 4.5.0
Thanks
Amit Anand
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.