Is it possible to populate the approved field (multiple group type) based on the product field value

Layssa Souza May 9, 2022

Hello guys,

 

I'm trying to create the following script:  When my field of type list is selected the option "AAA" my field of approvers (of the type multiple group) must fill with the group "AAA"
If it is the "BBB" option, you must fill in the "BBB" group and so on.

Is it possible to perform this configuration?

Below I share the script that I am customizing

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cat = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("Produto")
def selectListValue = cat.getClass()

def groupManager = ComponentAccessor.getGroupManager()
def multiGroupCf = customFieldManager.getCustomFieldObjectByName("Aprovadores") //multigroup picker custom field
//def changeAreaFieldObject = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_11200")


def TeamDatagroup = groupManager.getGroup("Aprovadores-técnicos-JIRA") //jira group
def BOgroup = groupManager.getGroup("Aprovadores-Linux") //jira group
def groupList = [TeamDatagroup]

if (cat in selectListValue == "Jira Software") {
issue.setCustomFieldValue(multiGroupCf, groupList)
}Configuration - script2.pngConfiguration - script.png

 

Best regards,

Layssa Souza

1 answer

1 accepted

1 vote
Answer accepted
Kawan Diogo May 9, 2022

Look, through the post function I couldn't reproduce the commented effect, but you can use Behaviors to assign a fixed value in the "Aprovadores" field.

 

It would be something like:

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

final singleSelectName = 'Produto'
final textFieldName = 'Aprovadores'

def singleSelect = getFieldByName(singleSelectName)
def singleSelectValue = singleSelect.value

def textField = getFieldByName(textFieldName)

//Set the appropriate value, dependent on the value of the currently selected single select option

switch (singleSelectValue) {

//Change 'Single Select Option...' to match your single select's values.

case 'Value A':
textField.setFormValue('Aprovadores-técnicos-JIRA')
textField.setReadOnly(true)
break
case 'Value B':
textField.setFormValue('Aprovadores-Linux')
textField.setReadOnly(true)
break

//Reset to default value if single select option is null or any other option that is not taken care of
default:

textField.setFormValue("")
}
Layssa Souza May 9, 2022

Hello @Kawan Diogo,

Thank you so much, this worked for me! :)

 

Best regards,

Layssa Souza.

Suggest an answer

Log in or Sign up to answer