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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,551,754
Community Members
 
Community Events
184
Community Groups

Auto update a multi select custom field based on Select List custom field

Saurabh Patel
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
Mar 29, 2023

Hi,

I am trying to create a Scriptrunner listener to auto update a multiselect field based on the value of a select list(while issue create and issue update). The below code shows no error, but it does nothing. Can someone correct this code or suggest a new one

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import com.atlassian.jira.issue.customfields.option.Options
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.issue.customfields.option.Options
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor
import groovy.transform.BaseScript


@BaseScript FieldBehaviours fieldBehaviours
def Field1 = getFieldById("customfield_56789")
String selectListValue = (String) Field1.getValue()


def selectField = getFieldById("customfield_56789")  //multiselect field
def selectCustomField = customFieldManager.getCustomFieldObject(selectField.fieldId)
def selectConfig = selectCustomField.getRelevantConfig(issueContext)
def selectOptions = ComponentAccessor.optionsManager.getOptions(selectConfig)

def selectAvailableOptions

if (selectListValue ='A')
{
selectAvailableOptions = selectOptions.findAll { it.value in ['AAAA'] }
}

else if (selectListValue ='B')
{
selectAvailableOptions = selectOptions.findAll { it.value in ['BBBB'] }
}

else
{
selectAvailableOptions = selectOptions.findAll { it.value in ['CCCC'] }

}

selectField.setFieldOptions(selectOptions.findAll{it.value in (selectAvailableOptions)})

0 answers

Suggest an answer

Log in or Sign up to answer