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

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

Vidhya Mohan February 21, 2020

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

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Jiri Kanicky February 22, 2020

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

Vidhya Mohan February 25, 2020

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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 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

Vidhya Mohan February 26, 2020

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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 26, 2020

Hi @Vidhya Mohan,

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

 

BR,

Leo 

Vidhya Mohan February 26, 2020

@Leo 

Default Value is set as none  :( 

Default Config.png

Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 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"])
Vidhya Mohan February 27, 2020

Thank you @Leo . It worked

TAGS
AUG Leaders

Atlassian Community Events