How to append value to the custom field (multi select) through post function?


I have a select type multi select custom field named 'Languages' and having values 'English', 'Spanish', 'Chinese', 'Hindi'.

Scenarios1: When user only selects Spanish, Chinese automatically append English through post function.

Like Spanish, Chinese, English.

Scenarios2: When user selects Chinese, Hindi automatically append English through post function.

Like Chinese, Hindi, English.

How to do that?


1 answer

1 accepted

Hi Teju,

Your custom script post function should be something similar to 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

def issue = issue as MutableIssue
def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("MultiSelectA")
def cfValue = issue.getCustomFieldValue(cf) as ArrayList

def optionsManager = ComponentAccessor.getOptionsManager()
def optionCCC = optionsManager.getOptions(cf.getRelevantConfig(issue)).find {it.value == "CCC"}
def optionAAA = optionsManager.getOptions(cf.getRelevantConfig(issue)).find {it.value == "AAA"}
def optionBBB = optionsManager.getOptions(cf.getRelevantConfig(issue)).find {it.value == "BBB"}

if (cfValue?.contains(optionAAA) && cfValue?.contains(optionBBB)) {
    def newValues = [optionCCC] + cfValue
    issue.setCustomFieldValue(cf, newValues)

Obviously you can edit the script above to meet your requirements. 

Hope that helps,

regards, Thanos

Hi Thanos,

It worked for me..

A thousand thanks to you..

Appreciated your quick reply.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

361 views 0 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you