Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Show/Hide field Based Cascading field selection

I have a cascading field called human.

When a user selects country on the first part of the cascading field. and selects Doctor on the second part of the cascading field. The field Total need to appear. For any other option, the total field must be hidden.  I am using scriptrunner behaviour for this one.

 

4 answers

1 accepted

2 votes
Answer accepted

Hello,

You should use ScriptRunner behaviours

1. Create a behaviour and add the cascading custom field to the behaviour.

2. Write a script for the added cascading field. Your script should be like this:

def cascField = getFieldByName("cascading field name")

def hiddenField = getFieldByName("name of your hidden field")

if (cascField.getValue().get("1") == "your value") {

      hiddenField.setHidden(true)

}

else {

   hiddenField.setHidden(false)

}

I just checked the code. It turned out that cascading fields work differently in behaviours. The value is actually an ArrayList. That is why your script should look like this:

def cascField = getFieldByName("cascading field name")

def hiddenField = getFieldByName("name of your hidden field")

def value = cascField.getValue() as ArrayList<String>

if (value.size() == 2 && value.get("1") == "your value") {

      hiddenField.setHidden(true)

}

else {

   hiddenField.setHidden(false)

}

I tried it and I get an error on the value.get("1") and I think this is because get only takes an integer.

 Hi @Alexey Matveev _cPrime_

 

I get an error on the if condition

 

The error is: Please check if the declared type is right and if the method exists

def cascField = getFieldByName("cascading field name")
def hiddenField = getFieldByName("name of your hidden field")

//hide by default
hiddenField.setHidden(false)

//create map
Map cfVal = cascade.getValue() as Map
if (cfVal){
if (cfVal.get(0) == "your value") {
hiddenField.setHidden(true)
}
}

you need to declare a map variable

hi @David STOCKY

 

This is my script

 

Other = getFieldById("customfield_10177")

 

if(status == "Apollo")    

{        apolloCategory.setHidden(false)

        apolloCategory.setRequired(true)

        apolloCategory.setHelpText("The Apollo category field is required, please provide information")   

            def cascField = getFieldByName("Apollo Category")
//create map

Map cfVal = cascField.getValue() as Map

if(cfVal) 

  {

        if(cfVal.get(0) == "Other")        

          Other.setHidden(true)        }

    }                        

  }

 

There are no errors now, but the other field is just not coming up or hidding

Is your field on the screen?

On which screen do you want to make it hide depending on cascading value? Create? Edit? View? Service Desk Portail?

To debug, you can add this code.

It will display information in jira log files

 

import org.apache.log4j.Logger
import org.apache.log4j.Level

def log = Logger.getLogger("com.behaviours")
log.setLevel(Level.DEBUG)

log.debug("text to display on log")

It's on the Create screen.

Are you sure that your customfiel (customfield_10177) is on the screen "Create" for your project?

Joe Pitt Community Leader Jun 07, 2018

@David STOCKY When does the script run? If when the screen appears the select fields will be empty. Wouldn't it need to run after the cascading field is populated? Could that be the problem? 

Normaly, the behaviours scripts should be on cascading field update if the script is define as server side.

In addition, behaviours mapping should be done on the right Project / issue type

Hello can anyone help me getting the cascading value in a custom field in behaviors.

My custom field has values in the following way:

Category[A,B,C]

If A is selected then the cascading list will show more values [A1,A2,A3].

I declared a Map variable and i tried many approaches. But I am going wrong somewhere. Would really appreciate some help here.

@Ramya Mani,

 

Did you resolve this? If yes, I would like to know the approach. The script is working fine, but the behaivours functionality seems to be incorrect in case of cascading,as it is not waiting for the child option to get selected and taking the first default child value.

Is there anything which I am doing? Please help me out here.

Hi All,

Following code has worked for me but ensure the cascading custom field is available in the screen you are working on,

For Behaviour:

def cfield = getFieldByName("cascading custom field name")
Map mapValue = cfield.getValue() as Map
def value1 = mapValue.get(0).toString()
def value2 = mapValue.get(0).toString()

For Post Functions:

import com.atlassian.jira.component.ComponentAccessor

def issueManager = ComponentAccessor.getIssueManager()

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObjectsByName('cascading custom field name').getAt(0)
def cstFldVlue = issue.getCustomFieldValue(customField)

Thanks

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you