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,455,915
Community Members
 
Community Events
176
Community Groups

Show multiple or one or none CF based on Multi Select field

Hi,

I have a multi select field (Customer Impacts) that has 3 options- Asset Management,  Branch Banker Support and Business Banking. I also have 3 number type fields - CI_AM, CI_BBS, CI_BB. (one for each options)

 

The requirement is, if I select any of the 3 options from the from the Multi select field, the corresponding number field should show. Example, if I pic Asset Management, CI_AM should show. If I pick both Asset Management and Business Banking both CI_AM and CI_BB should show and so on...

I tried several approach to achieve this but no luck. Any help is appreciated. 

 

 

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def CustomerImpactCF = getFieldByName("Customer Impacts")
def CI_AM_CF = getFieldByName("CI_AM")
def CI_BBS_CF = getFieldByName("CI_BBS")
def CI_BB_CF = getFieldByName("CI_BB")

def CustomerImpactCFValue =  CustomerImpactCF.getValue() as List

CustomerImpactCFValue.each() { CustomerImpactCFValueOption ->
  if ("Asset Management" in CustomerImpactCFValueOption.value) {
    CI_AM_CF.setFormValue('');
    CI_AM_CF.setHidden(false);
    CI_AM_CF.setRequired(true);
  }
 if ("Branch Banker Support" in CustomerImpactCFValueOption.value) {

    CI_BBS_CF.setFormValue('');
    CI_BBS_CF.setHidden(false);
    CI_BBS_CF.setRequired(true);
   
  }
  if ("Business Banking" in CustomerImpactCFValueOption.value) {
    CI_BB_CF.setFormValue('');
    CI_BB_CF.setHidden(false);
    CI_BB_CF.setRequired(true);

  }
  else {
    CI_AM_CF.setFormValue('');
    CI_AM_CF.setHidden(true);
    CI_AM_CF.setRequired(false);
    CI_BBS_CF.setFormValue('');
    CI_BBS_CF.setHidden(true);
    CI_BBS_CF.setRequired(false);
    CI_BB_CF.setFormValue('');
    CI_BB_CF.setHidden(true);
    CI_BB_CF.setRequired(false);
}


//}



1 answer

1 accepted

0 votes
Answer accepted

Hi @Joel Batac

For your requirement, you should try something like this:-

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

@BaseScript FieldBehaviours behaviours
def sampleMultiSelect = getFieldById(fieldChanged)
def sampleMultiSelectValue = sampleMultiSelect.value.toString()

def sampleNumber1 = getFieldByName('Sample Number 1')
def sampleNumber2 = getFieldByName('Sample Number 2')
def sampleNumber3 = getFieldByName('Sample Number 3')

sampleNumber1.hidden = true
sampleNumber2.hidden = true
sampleNumber3.hidden = true

if (sampleMultiSelectValue == '[Behaviour, Listener, Fragment]') {
sampleNumber1.hidden = false
sampleNumber2.hidden = false
sampleNumber3.hidden = false
} else if (sampleMultiSelectValue == '[Behaviour, Listener]') {
sampleNumber1.hidden = false
sampleNumber2.hidden = false
} else if (sampleMultiSelectValue == '[Behaviour, Fragment]') {
sampleNumber1.hidden = false
sampleNumber3.hidden = false
} else if (sampleMultiSelectValue == '[Listener, Fragment]') {
sampleNumber2.hidden = false
sampleNumber3.hidden = false
} else if (sampleMultiSelectValue == '[Behaviour]') {
sampleNumber1.hidden = false
} else if (sampleMultiSelectValue == '[Listener]') {
sampleNumber2.hidden = false
} else if (sampleMultiSelectValue == '[Fragment]') {
sampleNumber3.hidden = false
}

Please note that the sample code provided above is not 100% exact to your environment. Hence, you will need to make the required modifications.

Below are a few screenshots for your reference:-

1) When only the Behaviour option is selected from the Multi-Select List, only the Sample Number 1 field is displayed.

image1.png

2) When only the Listener option is selected from the Multi-Select List, only the Sample Number 2 field is displayed.image2.png

3) When only the Fragment option is selected from the Multi-Select List, only the Sample Number 3 field is displayed.

image3.png

4) When both the Behaviour and Listener options are selected from the Multi-Select List, both the  Sample Number 1 and Sample Number 2 fields are displayed.

image4.png

5) When both the Behaviour and Fragment options are selected from the Multi-Select List, both the  Sample Number 1 and Sample Number 3 fields are displayed.

image5.png

6) When both the Listener and Fragment options are selected from the Multi-Select List, both the  Sample Number 2 and Sample Number 3 fields are displayed.

 

image6.png

7) When all options are selected from the Multi-Select List, all the Number fields are displayed.

image7.png

I hope this helps to answer your question. :)

Thank you and Kind regards,

Ram

Thanks Ram. Is it possible to do a  loop? In reality the multi select field contains 27 options ( i just gave a 3 for simplicity)

Hi @Joel Batac

There is no simple way for this.

Making a loop will not work as expected and will cause errors.

Thank you and Kind regards,

Ram

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events