I created a database picker field that has a value from one of the columns from the customer table in the database. I have multiple custom fields that I want to make hidden. The only time it should display those fields is if the user selects a value from the DB Picker field.
I would like to have those fields hidden all the time but whenever the user selects a value then those fields should be visible. I mean when it's empty fields should be hidden when there is a value then fields should be visible. I tried a behaviour script but it didn't display fields. Not sure what I'm doing wrong.
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def locationName = getFieldById('customfield_15401')
def cusName = getFieldById('customfield_18502')
cusName.setHidden(true)
if(locationName.value == ' ') {
cusName.setHidden(true)
}
else {
nameField.setHidden(false)
}
Thank you for your help
Hi @Shah Baloch
def customField = getFieldById(getFieldChanged()).getValue().toString()
if ( customField == "optionValue"){
getFieldById("Custom field_10301").setHidden(true);
}
Can you try this code and let me know!!
Thanks,
Pramodh
Hi @Pramodh M thank you for your response. I'm having trouble understanding the code that you provided. I'm not sure where I can add my first DB picker field "customfield_15401" that its value can make another field "customfield_18502" visible.
I would like the second custom field to behave based on the first field's value. The second custom field should be hidden by default. If a customer selects a value from the DB picker field "customfield_15401" then the second field should become visible otherwise it should remain hidden.
My coding skills are limited. Can you please write the complete code for me? I appreciate your help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Shah Baloch
Add the Behaviour to DB Picker field
and add the script below
In the optionValue place add the actual value in your DB Picker Field Option
def customField = getFieldById(getFieldChanged()).getValue().toString()
if ( customField == "optionValue"){
getFieldById("customfield_18502").setHidden(false);
}
else {
getFieldById("customfield_18502").setHidden(true);
}
Let me know if you have any further queries
Thanks,
Pramodh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you @Pramodh M the DB Picket field contains more than 100 values options. Adding all values will cause issues maintaining the script. It is the location field, when the user is creating an issue if a user is reporting an issue about a specific location they will select one of the locations, once the value is selected then other fields should become visible otherwise hidden. Isn't there any other way to make it work without adding option values? I mean without adding option values in the script.
Thank you for your help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try this out. It just looks to see if there is a value in the the custom field. If the field does not have a value then the other field won't show.
def customField = getFieldById(getFieldChanged()).getValue()
if (customField){
getFieldById("customfield_18502").setHidden(false);
}
else {
getFieldById("customfield_18502").setHidden(true);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Tim Perraultthank you for your response. A team member reached out to the Adaptavist support and they helped us to make it work. Here is the working coding that we added in both the Initializer and Behaviour sections. Hope it can be helpful for others.
def userName = getFieldById('customfield_18507')
def numOfDevices = getFieldById('customfield_18504')
if (!userName.value) {
numOfDevices.setHidden(true)
}
else {
numOfDevices.setHidden(false)
}
Thanks
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.