How to retrieve value from Team field

Ponnappan Ganapathiya February 23, 2024

Does any one know how to get value from the custom field "Team" which is created by Advanced roadmaps for Jira.

In JQL it runs with team id. When I try to use it in a workflow condition with Scriptrunner, its not working.

 

cfValues['Team']?.value == '45'

2 answers

1 accepted

0 votes
Answer accepted
Ponnappan Ganapathiya February 23, 2024

The question I raised is to achieve the workflow condition. Since the custom script not working, I changed it to validate via JQL. That made the condition to work as expected.

 

And, the script that worked 

import com.atlassian.jira.component.ComponentAccessor

def team = ComponentAccessor.customFieldManager.getCustomFieldObject(12345) // replace this with your Team field iddef teamValue = issue.getCustomFieldValue(team)?.description?.title

teamValue == "Test"

Thanks to Winnie from Adaptavist

0 votes
Matt Parks
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 23, 2024

Using Scriptrunner, I created the following script field

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.rm.teams.core.team.data.DefaultTeam
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.atlassian.rm.teams.api.team.GeneralTeamService
import com.atlassian.crowd.embedded.api.Group

@WithPlugin("com.atlassian.teams")


def teamField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName('Team').first()
def teamValue = (DefaultTeam) issue.getCustomFieldValue(teamField)
def teamName

if (teamValue)
{
    teamName = teamValue.getDescription().getTitle()
    return teamName
}

return null
Ponnappan Ganapathiya February 23, 2024

HI Matt,

I am quite confused here.. What do you mean by Default Team?

 

Matt Parks
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 23, 2024

DeafultTeam is the class that you have to cast the value in the Team field as when you pull it out from the issue. I'm not sure why it was built that way, but that's how it works.

My guess is that is has something to do with the fact that all of this functionality used to be part of the Portfolio/Advanced Roadmaps plugin before it was integrated into Jira directly.

Like Ponnappan Ganapathiya likes this
Ponnappan Ganapathiya February 23, 2024

groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.fields.ImmutableCustomField.first() is applicable for argument types: () values: [] Possible solutions: print(java.io.PrintWriter), print(java.lang.Object), find(), find(groovy.lang.Closure), is(java.lang.Object), printf(java.lang.String, [Ljava.lang.Object;) at Team.run(Team.groovy:14)

 

It seems there is some error in getting the value..

Matt Parks
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 23, 2024

If you look in the list of custom fields, do you have a field called Team? I'm assuming you do, but want to make sure.

Also, in case it isn't clear, the "def teamField = " and "ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName('Team').first()" should all be on the same line. It's just a limitation of the Community format that it looks like they aren't.

Ponnappan Ganapathiya February 23, 2024

To make it more clear I get the field by custom field id... The field is accessible but somewhat its not retrieve the data values...

Ponnappan Ganapathiya February 23, 2024

Hi Matt, 

Thanks for your time. I changed the condition script to work based on JQL. Its working fine.

Anyway I will try to work on this to extract the value from the Team field, probably via rest call.

Ponnappan Ganapathiya March 4, 2024

The following works with custom field condition on a workflow:

import com.atlassian.jira.component.ComponentAccessor

def team = ComponentAccessor.customFieldManager.getCustomFieldObject(12345) // replace this with your Team field iddef teamValue = issue.getCustomFieldValue(team)?.description?.title

teamValue == "Test"

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events