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

Set Organisation to user

ian mirfin August 22, 2017

I would like to set the organisation for a user on a transition.

Using the organisation linked to an issue then I want to assign the same organisation to a customer.

I am attempting to use this function but cannot get it working, I know its not right any assistance would be greatly appreciated

addUsersToOrganization

@WithPlugin("com.atlassian.servicedesk")

@PluginModule
ServiceDeskManager serviceDeskManager

@PluginModule
OrganizationService organizationService

ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def cfOrganisation = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Organizations")
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cfUserPicker = customFieldManager.getCustomFieldObject(11901L)
def organisation = issue.getCustomFieldValue(cfOrganisation)

ApplicartionUser user = issue.getCustomFieldValue(cfUserPicker)

UsersOrganizationUpdateParameters param = organizationService.newUsersOrganizationUpdateParameters().customerOrganisation(organisation).users(newUser).build()
organizationService.addUsersToOrganization(user, param)

 

 

1 answer

1 vote
Vasilii Gustelev March 7, 2018

Hey Ian,

I've managed to get your code working, so for everyone else looking for an example, here is a solution:

 

@WithPlugin("com.atlassian.servicedesk")

@PluginModule
ServiceDeskManager serviceDeskManager

@PluginModule
OrganizationService organizationService

ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def cfOrganisation = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Organizations")
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cfUserPicker = customFieldManager.getCustomFieldObject(11901L)
def organisation = issue.getCustomFieldValue(cfOrganisation)

ApplicartionUser user = issue.getCustomFieldValue(cfUserPicker)

Set<com.atlassian.jira.user.ApplicationUser> users =  [newUser]
UsersOrganizationUpdateParameters param = organizationService.newUsersOrganizationUpdateParametersBuilder().organization(org).users(users).build()
organizationService.addUsersToOrganization(user, param)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events