Set Team field to default value

Originally asked by Michal Sitkey on 23 September 2021 (original question)


Hi,

We have Jira to Jira connection where we are facing errors when issue is created where is validator set to Team field must be populated.

We need to set Team field to Default value.

This is not working for us :

issue.customFields.“Team”.value = “Team Name”

As we dont know what type is Team field can Exalate help us with code to set Team field a default value to not faced errors?

Thanks for help


Comments:

Serhiy Onyshchenko commented on 30 September 2021

Hello, Michal Sitkey .
Is this for Jira on-premise or Jira Cloud?

Michal Sitkey commented on 30 September 2021

Jira is server version (no Cloud)

Answer by Daniel Carvajal on 29 April 2022

We have finally tested and implemented the following snippet to be used in the Incoming script:

def setTeamField = {
    String targetTeam ->
    
    
    def var = replica.customFields."Team"?.value?.description?.shareable?.asBoolean
    def pluginAccessor = com.atlassian.jira.component.ComponentAccessor.getPluginAccessor()
    def teamsPlugin = pluginAccessor.getEnabledPlugin("com.atlassian.teams")
    if (teamsPlugin == null) {
        //no teams plugin
        return
    }
    
    
    def teamsCl = teamsPlugin.classLoader
    def teamsCa = teamsPlugin.containerAccessor
    def tservClass = teamsCl.loadClass("com.atlassian.rm.teams.api.team.FullEnrichedTeamService")
    def _DefaultTeamDescription = teamsCl.loadClass("com.atlassian.rm.teams.api.team.data.DefaultTeamDescription")
    def _Optional = teamsCl.loadClass("com.google.common.base.Optional")
    def tserv = teamsCa.getBeansOfType(tservClass).first()
    def teamIds = tserv.getTeamIdsWithoutPermissionCheck()
    def teams = tserv.getTeams(teamIds)
    
    def team = teams.find { t -> t.description.title == targetTeam } //?: createTeam()
    //debug.error("this is the result of the team field: ${team}")
    
    
    issue."Team" = team
}
def targetTeam = replica.customFields."Team"?.value?.description?.title?.asString ?: "Team3" //change for default team to be set if no team field value is sent from the remote side 

if(firstSync && replica.project.key == "KANS"){
   issue.projectKey   = "KAN"
   issue.typeName     = nodeHelper.getIssueType(replica.type?.name, issue.projectKey)?.name ?: "Task"
  
   setTeamField(targetTeam) //Method to be called to set the field
}

The field can be sent in the outgoing script like this:

replica.customFields."Team" = issue.customFields."Team"

Answer by Jose Lobo on 23 September 2021

Hey Michal Sitkey ,

Which doc were you referring to when writing this script?

This doc might help you > How to Set Default Values in a Custom Field.


Comments:

Michal Sitkey commented on 23 September 2021

Team field is from Jira Roadmaps plugin.

Michal Sitkey commented on 24 September 2021

Yes im trying with this, but Team field is specific from Jira Roadmaps and also type of this field is Team field type in custom fields. Than i dont know what to choose and how to set default value for this field.

Jose Lobo commented on 24 September 2021

What type of field is it? (free text, select list, radio button, checkbox)

Michal Sitkey commented on 27 September 2021

Its reason why im writing this question. Team field is from Jira Roadmaps addon and in custom fields tab have custom field type TEAM …Nothing from these what you write.

Francis Martens (Exalate) commented on 13 March 2022

Hi Michal Sitkey

So - what you need is a way to know what the default value is for the team name?

Michal Sitkey commented on 14 March 2022

No we need to team field a default value from connector inside of Exalate to overcome validator what is checking if team is presented inside of Issue. Than team must be set in process of creating of issue.

Michal Sitkey commented on 14 March 2022

set a team field a default value

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.