Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Set Portfolio-for-Jira Team field value


I want to assign a portfolio Team to a card based on the Jira project. For example: 

In my listener, if the issue being created is in Project "KSB" then the Portfolio Team field should be set to <team of my choice>

My problem: I am currently unable to set the Portfolio Team field's value using a string or an integer. What can I pass into the updateValue method as the updated value for the portfolioTeamField?

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.index.IssueIndexingService
import org.apache.log4j.Logger
import org.apache.log4j.Level

def issue = event.issue as Issue

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def portfolioTeamField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName("Team")[0]
def changeHolder = new DefaultIssueChangeHolder()
def issueIndexManager = ComponentAccessor.getComponent(IssueIndexingService)
def PTFValue = issue.getCustomFieldValue(portfolioTeamField)

if (issue.projectObject.key == "KSB"){

//I NEED TO SET THE TEAM FIELD VALUE BELOW, BUT GET A TYPECAST ERROR, what replaces <portfolio team of my choice>

//portfolioTeamField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(portfolioTeamField), <portfolio team of my choice>),changeHolder)



If I try to set that field using a string I get the typecast err below: 

2020-05-13 14:20:18,725 ERROR [runner.AbstractScriptListener]: *************************************************************************************
2020-05-13 14:20:18,726 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: null
java.lang.ClassCastException: java.lang.String cannot be cast to
	at com.atlassian.jira.issue.fields.ImmutableCustomField.createValue(
	at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(
	at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(
	at com.atlassian.jira.issue.fields.OrderableField$ Source)

If I manually set the field via the GUI and then log it's value this is what I get:

2020-05-13 14:31:58,687 DEBUG [runner.AbstractScriptRunner]: PorfolitoTeamField =Team
2020-05-13 14:31:58,687 DEBUG [runner.AbstractScriptRunner]: PTFValue =5
2020-05-13 14:31:58,687 DEBUG [runner.AbstractScriptRunner]: PTFValue Title = Profiles
2020-05-13 14:31:58,687 DEBUG [runner.AbstractScriptRunner]: PTFValue Description =  

But back to my original question I can't simply set the value to "Profiles" as a string, I am stuck please help! 

1 answer

1 accepted

0 votes
Answer accepted

In order to set the Team field, we will need to provide a value whose type is We can get one of these by using the GeneralTeamService:

import com.onresolve.scriptrunner.runner.customisers.WithPlugin

import com.onresolve.scriptrunner.runner.customisers.PluginModule



@PluginModule GeneralTeamService teamService 

def team = teamService.getTeam(123).get()

where 123 is the numerical ID of the team. If you need a complete list of IDs for all your teams, for reference purposes, then you can run the following in the Script Console:

import com.onresolve.scriptrunner.runner.customisers.WithPlugin

import com.onresolve.scriptrunner.runner.customisers.PluginModule

import @WithPlugin("com.atlassian.teams")

@PluginModule GeneralTeamService teamService 

teamService.teamIdsWithoutPermissionCheck.collectEntries {[(it) :teamService.getTeam(it).get()?.description?.title]}

which will show you the ID and name of every team.



Thank you very much for this post.

Is there method documentation for  documentation GenralTeamService?

Nevermind, I was able to use JMWE Scripted (Groovy) Post-function to look up the methods using the package name.

ANyway, thank you very much for this post, as it simplifies my code for finding the team ID based on its name from:

//Get the total number of teams in the system
def int teamCount = (int)teamAPI.count()
if((teamCount%MAX_TEAMS_PER_CALL) > 0){
teamCount = (teamCount/MAX_TEAMS_PER_CALL) + 1;
teamCount = (teamCount/MAX_TEAMS_PER_CALL);

//Itterate throught each 100 teams
for (int i = 1; i <= teamCount; i++){
Iterator <TeamDTO> teamsIterator = teamAPI.findAll(i, MAX_TEAMS_PER_CALL).iterator();
TeamDTO team = (TeamDTO);
//Check if the team name matches the one in FNMTeam field
if (team.title.value().equals(fnmTeamFieldValue)){
teamID =;

To this:

//Get the map of all team names and corresponding IDs
def teamMap = teamService.teamIdsWithoutPermissionCheck.collectEntries {[(teamService.getTeam(it).get().description.title) :(it)]};

//Get the team ID corresponding to the FNMTeam field value
def teamID = teamMap.get(fnmTeamFieldValue)?.value;

Hey, Can you please share the syntax for  

what should be the value for teamDescription in order to create a team field using teamService.createTeam method. 
Or is there a better approach to create team using ScriptRunner. Please suggest. 

Suggest an answer

Log in or Sign up to answer

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you