How to set Issue Organisations from Groovy Script

Tomi Hakkarainen
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 14, 2018

If I query  Issue with correct data in place I get this:

 

def customFieldManager = ComponentAccessor.getCustomFieldManager();
def Orgfield = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Organizations")

def OrgFieldValue = issue.getCustomFieldValue(Orgfield);

log.info("OrgFieldValue: " + OrgFieldValue);

log.info("OrgFieldValueClass: " + OrgFieldValue[0].getClass());

log Output:

OrgFieldValue: [CustomerOrganizationImpl{id=8, name=Testi Asiakas}]

OrgFieldValueClass: class com.atlassian.servicedesk.internal.feature.organization.model.CustomerOrganizationImpl

I know I can update empty array list with this:

Orgfield.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(Orgfield), updatedOrgFieldValue),new DefaultIssueChangeHolder());

but I have not been able to figure out how to construct correct "Object" for input "CustomerOrganizationImpl" to set empty Customfield with ArrayList

 

Any help/info would be highly appreciated

1 answer

1 vote
Paul Grove
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 5, 2024

Hey this has taken me a significant amount of time to work out, so I'll post the answer here for future searchers, the problem stated is how to get a specific `CustomerOrganizationImpl` so that it can be added to the Organizations field.

To get a list of CustomerOrganizationImpl:

// get an instance of the OrganizationService:
def classLoader = ComponentAccessor.pluginAccessor.classLoader
def organizationService = ComponentAccessor.getOSGiComponentInstanceOfType(classLoader.findClass('com.atlassian.servicedesk.api.organization.OrganizationService'))

// build an instance of OrganizationsQuery:
def organizationQuery = organizationService.newOrganizationsQueryBuilder().build();

// get a List of all CustomerOrganizationImpl:
def organizations = organizationService.getOrganizations(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(), organizationQuery).getResults();

from there you have a list of all the Organizations, I have only one, and the list looks like this:

[CustomerOrganizationImpl{id=1, name=Test}] 

You can use the values in this list to update the OrgFieldValue in the original question.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events