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
@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)
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.