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