Tempo Team custom field

The script snippets show you how to get the value of the Team custom field of an issue and how to write a Tempo team into a Jira issue.

With the version 8 of Tempo Teams (included in Tempo Planner Version 8, Tempo Budgets Version 14 and Tempo Timesheets Version 11) the Tempo Team field has been converted into an object. Previously (Tempo Teams 6 and older) the Tempo Team field was returned with an ID of the Tempo team.

In all cases you should import the following dependencies and you can access the Tempo custom field on an issue as follows:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.fields.CustomField import com.onresolve.scriptrunner.runner.customisers.PluginModule import com.onresolve.scriptrunner.runner.customisers.WithPlugin import com.atlassian.jira.issue.MutableIssue import org.apache.log4j.Level import org.apache.log4j.Logger import com.tempoplugin.team.service.TeamImpl import com.tempoplugin.team.api.Team import com.tempoplugin.team.api.TeamImpl import com.tempoplugin.team.api.TeamManager import com.tempoplugin.team.api.TeamService import groovy.transform.Field import com.onresolve.scriptrunner.runner.ScriptRunnerImpl import com.atlassian.jira.event.type.EventDispatchOption @WithPlugin("com.tempoplugin.tempo-teams") @PluginModule TeamService teamService def myLog = Logger.getLogger("com.onresolve.jira.groovy") myLog.setLevel(Level.DEBUG) def IssueManager = ComponentAccessor.getIssueManager() MutableIssue issue = IssueManager.getIssueObject("WIKK-20") def customFieldManager = ComponentAccessor.customFieldManager def teamField = customFieldManager.getCustomFieldObjects(issue).find { it.name == "Team" } if (!teamField) return; def team = issue.getCustomFieldValue(teamField)

Now you can output the Tempo Team field

1 myLog.info("Team: " + team)

For Tempo Teams 7 and below this will return the Team ID. If you want to display e.g. the Team Name you will need to do

1 2 def tempoteamobject = teamService.getTeam(team.toInteger()).getReturnedValue() myLog.info("Tempo Team name: " + tempoteamobject.name)

To update an issue with a new Tempo Team you will need to

1 2 3 def newteam = "GreenCloud Tango" issue.setCustomFieldValue(teamField, newteam) ComponentAccessor.issueManager.updateIssue(ComponentAccessor.jiraAuthenticationContext.getLoggedInUser(), issue, EventDispatchOption.ISSUE_UPDATED, false)

WIth the version of Tempo Teams 8 and above the behaviour of the Tempo Team custom field changes. Now will

1 myLog.info("Team: " + team)

return the Team custom field name and the following will now throw an error:

1 2 def tempoteamobject = teamService.getTeam(team.toInteger()).getReturnedValue() myLog.info("Tempo Team name: " + tempoteamobject.name)

You will now be able to access the Tempo Team information with:

1 myLog.info("Tempo Team name: " + team.name + " with an ID: " + team.id)

To update the Tempo team on an Jira issue you will need to declare/pass the Tempo team as an object. This can be done with:

1 2 3 def newteam = teamService.getTeamByName("Custom Web Development").getReturnedValue() issue.setCustomFieldValue(teamField, newteam) ComponentAccessor.issueManager.updateIssue(ComponentAccessor.jiraAuthenticationContext.getLoggedInUser(), issue, EventDispatchOption.ISSUE_UPDATED, false)