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.
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)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried it and I get an error on the value.get("1") and I think this is because get only takes an integer.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Suresh,
Can you please share the complete behaviour code that you have implemented to pull in the desired result.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I get an error on the if condition
The error is: Please check if the declared type is right and if the method exists
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Are you sure that your customfiel (customfield_10177) is on the screen "Create" for your project?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.