Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Portfolio for Jira "Team" Field? Edited

I have a Portfolio for Jira Team field and I am trying to set it's value using a script runner script. 

 

def PTFValue = issue.getCustomFieldValue(portfolioTeamField)



As you can see, I can log the "value", "title" and "description" but when I try to pass the "value" of 5 into a setCustomFieldValue method I get a type cast error.

How do I access all of the options for that field and assign them to unique variables? They are not simply strings, as the logs show. Even though the "title" of that Team object is Profiles I cannot pass the string Profiles as a value for that field.  The "Description" value (calling PTFValue.getDescription()) appears to change when logged at different run times. 

 

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 = com.atlassian.rm.teams.api.team.data.DefaultTeamDescription@6ce8214c  



I need to assign the Team field's value but I cannot use a string or number. I want to access all of the Team field's options but I am unable to do so. 

Is there some trick to access Portfolio For Jira fields? Any documentation that may help? 

 

Thank you! 

1 answer

1 accepted

1 vote
Answer accepted

In order to set the Team field, we will need to provide a value whose type is com.atlassian.rm.teams.api.team.Team. We can get one of these by using the GeneralTeamService:

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

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

import com.atlassian.rm.teams.api.team.GeneralTeamService 

@WithPlugin("com.atlassian.teams")

@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 com.atlassian.rm.teams.api.team.GeneralTeamService @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.

Hello Judeboy, 
I'm trying to run your code to get a complete list of IDs for all my teams and I'm running into the following error after copying and pasting your code into the script console.

 

The script could not be compiled: <pre>org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script36.groovy: 5: unexpected token: @ @ line 5, column 59. s.api.team.GeneralTeamService @WithPlugi ^ 1 error </pre>

Logs:

2021-02-23 13:31:08,254 ERROR [common.UserScriptEndpoint]: ************************************************************************************* 2021-02-23 13:31:08,258 ERROR [common.UserScriptEndpoint]: Script console script failed: groovy.lang.MissingPropertyException: No such property: teamService for class: Script34 at Script34.run(Script34.groovy:2)

 

Any ideas?

Suggest an answer

Log in or Sign up to answer
TAGS

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