Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to reset value on a single select field on selection of another single select

tazeenn April 30, 2019

Hi,

I am using a behaviour script to populate the value of single select field based on another singlke select field selection

Selectlist1 (Role Name) has name of Roles

Selectlist 2 (VPN) - Has options Yes & No

My script is working fine when selecting role name , select list 2 is getting select as Yes 

However the issue is that once yes is populated on the select list 2, its not getting deselected on selecting other roles. Ideally, it should turn none, or no for roles that are not in if condition.

Please help on helping me with finding a way to deselect the value from Yes. Basically its not going to else condition. Once the Role is sleected and VPN populates "Yes", it not deselected to "No" even if you change role names

Here is my script

import com.atlassian.jira.component.ComponentAccessor
import groovy.transform.BaseScript
import com.atlassian.jira.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.fields.config.FieldConfigImpl


@BaseScript FieldBehaviours fieldBehaviours

def optionsManager = ComponentAccessor.getOptionsManager()

// Get the Custom Field Manager
def customFieldManager = ComponentAccessor.getCustomFieldManager()

// Get a pointer to my select list custom fields
def selectList1 = getFieldByName("Role Name")
def selectList2 = getFieldByName("VPN")

// Get the value of selectList1
def selectList1Val = selectList1.getValue()

// If Select List 1 is set to hosting then set selectList2 to option B
if(selectList1Val.toString().contains("Hosting")){
// Set the value to the ID of option B
selectList2.setFormValue("Yes")
selectList2.setReadOnly(true)
}

else if (selectList1Val.toString().contains("DevOps")){
// Set the value to the ID of option B
selectList2.setFormValue("Yes")
selectList2.setReadOnly(true)
}

else if (selectList1Val.toString().contains("Tech Lead")){
// Set the value to the ID of option B
selectList2.setFormValue("Yes")
selectList2.setReadOnly(true)
}

else if (selectList1Val.toString().contains("Release Team")){
// Set the value to the ID of option B
selectList2.setFormValue("Yes")
selectList2.setReadOnly(true)
}

else if (selectList1Val.toString().contains("QA")){
// Set the value to the ID of option B
selectList2.setFormValue("No")
selectList2.setReadOnly(true)
}

//else {selectList2.setFormValue(null)
// selectList2.setReadOnly(true)
//}

 

script2.png

1 answer

0 votes
Richard Jenkins
Contributor
December 3, 2019

Hi Tazeenn, have you tried changing the (selectList1Val.toString().contains() to (selectList1Val.toString().equals()

This was the only change I did and it worked as expected. Let us know!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events