I have the following fields in our assign screen :
- Incident category
- Incident item.
- Incident summary.
- Technician office code
- select name
on one screen whenever our users select the category and item and summary from the dropdown they will have to select the technician office code and the name of the individual will be displayed in the select name field.
The issue we are facing is that whenever we try to click on the other options in incident category for eg incident category has two options crm and hrms then if user selects crm the technician list name of that category will appear and when the user selects hrms the technician list of that category should appear but however when we try to change the category from CRM to HRMS the values of select name are not changing it retains the old category value .
We have two values in technician office code "109897" and "Company" we have to toggle between theses two options eg. first click on 109897 and then click on "Company" to update the field select name with correct value .
Is there any function which can update the value of select name as soon as the category is changed.
We are using below code to set the name field
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.bc.user.search.UserSearchService
def id = getFieldById("id")
def currentIssue = ComponentAccessor.getIssueManager().getIssueObject(Long.parseLong(id.getValue() as String))
String Technician_Office_Code = currentIssue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_161")) as String
log.error"Technician office code"+Technician_Office_Code
if(getFieldById(getFieldChanged()) != null ){
String assigneeName = getFieldById(getFieldChanged()
def selectAssignee = getFieldById("customfield_12")
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObject(selectAssignee.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
List<Option> optionsSelect = new ArrayList<Option>()
def userSearchService = ComponentAccessor.getComponent(UserSearchService)
def users = userSearchService.findUsersByFullName(assigneeName)
List<String> test = new ArrayList<String>()
for(def user : users){
// test.add(user.getUsername())
test.add(user.getName())
}
for(String optionStr : test){
boolean f = true
for(def option : options){
if(option.getValue().trim().equals(optionStr.trim())){
optionsSelect.add(option)
f = false
break
}
}
if(f){
optionsSelect.add(optionsManager.createOption(config, 0, 0, optionStr))
}
}
def selected = [:]
selected += optionsSelect.collectEntries{
[(it.optionId.toString()) : it.value]
}
//log.error"-------------xxxxxx79xxxxxxx----"+optionsSelect
selectAssignee.setFieldOptions(selected)
}else{
getFieldById("customfield_12").setHidden(true)
getFieldById("customfield_12").setRequired(false)
getFieldById("customfield_12").setFormValue(null)
getFieldById(getFieldChanged()).setFormValue(null)
}