Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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

Behavior Plugin - Add an addtional value to a drop down based on another field vale

can someone share a sample script to add a value to a dropdown based on value selected in another field

 

I need to add an additional value 'Existing Prod Value' to a field Dev RCA when 'Detected in Test Stage' is NOT Warranty or Prod

1 answer

1 accepted

0 votes
Answer accepted

The script in here will show you how to list different options for single select list field based on selection from other list field.

You can try to add new option to the list and test if its saved. I am not sure about that part.

https://community.atlassian.com/t5/Adaptavist-questions/Behavior-script-for-field-dependecy/qaq-p/1304574

thanks @Jiri Kanicky 

Can you please let me know why this is not working for me? Also I want to set None as the default value.

import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager

//Get Relevant field and options manager
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()

def detectedinteststageField = getFieldById(getFieldChanged())
def selectedOption = detectedinteststageField.getValue() as String
def cfDevRCA = getFieldById("customfield_18408")

def customField = customFieldManager.getCustomFieldObject(cfDevRCA.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)

if(selectedOption != "5-Warranty" || selectedOption != "7-PROD"){
def optionsMap = options.findAll {
it.value in ["None", "Ambiguous requirement" , "Code merging" , "Data quality issue" , "Design documentation issue - E2E sheet" , "Design gap - FDD" , "Design gap - TDD" , "Developer Oversight" , "Existing prod issue" , "Impact not analysed - Cross project impact" , "Impact not analysed - Incomplete analysis" , "Impact not analysed - Regression/Defect fix" , "Improper reconciliation" , "Incomplete implementation/defect fix in ST/UAT/Prod" , "Incorrect configuration" , "Incomplete implementation" , "Incorrect logic" , "Incorrect solution" , "Induced due to PRS" , "Interface changes/mismatch" , "Lack of system understanding" , "Package issue" , "Retrofit missed" , "Scenario coverage/Incomplete unit testing"
] // list of options you want to show
}.collectEntries {[(it.optionId.toString()): it.value]}
cfDevRCA.setFieldOptions(optionsMap)
}
else{
def optionsMap = options.findAll {
it.value in ["None", "Ambiguous requirement" , "Code merging" , "Data quality issue" , "Design documentation issue - E2E sheet" , "Design gap - FDD" , "Design gap - TDD" , "Developer Oversight" , "Impact not analysed - Cross project impact" , "Impact not analysed - Incomplete analysis" , "Impact not analysed - Regression/Defect fix" , "Improper reconciliation" , "Incomplete implementation/defect fix in ST/UAT/Prod" , "Incorrect configuration" , "Incomplete implementation" , "Incorrect logic" , "Incorrect solution" , "Induced due to PRS" , "Interface changes/mismatch" , "Lack of system understanding" , "Package issue" , "Retrofit missed" , "Scenario coverage/Incomplete unit testing"
] // list of options you want to show
}.collectEntries {[(it.optionId.toString()): it.value]}
cfDevRCA.setFieldOptions(optionsMap)
}
Leo Community Leader Feb 25, 2020

Hi @Vidhya Mohan,

Couple of things on this

1. you want this change should happen if the selected option is neither  Warranty nor Prod right? then the condition should be 

if(selectedOption != "5-Warranty" && selectedOption != "7-PROD")

2. "None" is not a option unless you created one for that field. it is empty value provides by system. if you leave that part system will always fill the form field with None(if there is no default value is configured). it's better to remove that option from your script

 3. without  checking apart from None option looks good to me. do you get any error? if so can you pass me the same to check 

 

Note:  Remove // list of options you want to show I just added to explain that part in my previous script

 

BR,

Leo

Hello @Leo 

 

thanks. this worked. But issue is it always selects 'Ambiguous requirement' as the default value. How to get this changed? I want either blank or None as the default value. 

Leo Community Leader Feb 26, 2020

Hi @Vidhya Mohan,

Check the configuration of that field and remove default value configured for the same

 

BR,

Leo 

@Leo 

Default Value is set as none  :( 

Default Config.png

Leo Community Leader Feb 26, 2020

You can try this method, I haven't tried by myself but hopefully this should do what you are looking for

cfDevRCA.setFieldOptions(optionsMap + ["-1": "None"])

Thank you @Leo . It worked

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Admins, notify your Jira instance of system-wide changes with the new admin announcement banner

Hi All! We’re excited to share the launch of an announcement banner that lets Jira site administrators communicate directly to their users across their  Jira Cloud instance.  ...

595 views 15 18
Read article

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