Portfolio Java API: How can I update the value for Portfolio's "Team" field?

We are currently customizing Jira Portfolio for a customer who wants to have set default teams for several projects.

I was happy to find the Portfolio Java API but it doesn’t work as expected. I get an exception “com.atlassian.rm.teams.publicapi.interfaces.team.TeamDTO cannot be cast to com.atlassian.rm.teams.api.team.Team”.

The code I am using in ScriptRunner is as follows:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption

def issueManager = ComponentAccessor.issueManager
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def user = ComponentAccessor.getJiraAuthenticationContext().loggedInUser

def teamCf = customFieldManager.getCustomFieldObjectsByName('Team').first()

def issueToSet = issueManager.getIssueObject('XYZ')
long teamIdToSet = 41l

def pluginAccessor = ComponentAccessor.getPluginAccessor()
Class teamAPIClass = pluginAccessor.getClassLoader().findClass("com.atlassian.rm.teams.publicapi.interfaces.team.TeamAPI")

def teamAPI = ComponentAccessor.getOSGiComponentInstanceOfType(teamAPIClass)
def teamValueGenerated = teamAPI.findById(teamIdToSet).value()

issueToSet.setCustomFieldValue(teamCf, teamValueGenerated)
issueManager.updateIssue(user, issueToSet, EventDispatchOption.ISSUE_UPDATED, false)

How can I make the cast work or what is an appropriate way to update the Team Field programmatically?

Thanks in advance


Hi Daniel,

Could you solve this problem?