I have two select list fields in create screen if i change one filed the other filed should change . how to write a script in a groovy using script runner
Here is an example which sets the steps to reproduce field to "First" when the LOB field is set to "AAA". Otherwise steps to reproduce is set to None. You should be able to adapt this for your use case.
import com.atlassian.jira.component.ComponentAccessor def stepsToReproField = getFieldByName("Steps to Reproduce") def lobField = getFieldById(getFieldChanged()) def optionsManager = ComponentAccessor.getOptionsManager() def customFieldManager = ComponentAccessor.getCustomFieldManager() def customField = customFieldManager.getCustomFieldObject(stepsToReproField.getFieldId()) def config = customField.getRelevantConfig(getIssueContext()) def options = optionsManager.getOptions(config) // If LOB field is AAA set other field to First value if (lobField.value == "AAA") { def optionToSelect = options.find { it.value == "First" } stepsToReproField.setFormValue(optionToSelect.optionId) } else { // Default to None if not AAA value stepsToReproField.setFormValue(null) }
Hope this helps.
Adam
def otherFaveField = getFieldByName("Steps to Reproduce") def faveFruitField = getFieldById(getFieldChanged()) def selectedOption = faveFruitField.getValue() as String log.debug("selected value " +selectedOption) def isOtherSelected = selectedOption == "PowerEdge" log.debug("Isother selected " +isOtherSelected) otherFaveField.setHidden(! isOtherSelected) otherFaveField.setRequired(isOtherSelected)
Two customfileds:
1.LOB
2.Steps to Reproduce
I tried with this code by adding as a server side script for LOB(customfiled) but nothing seems to work. when i change source field value (LOB).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry that didn't quite do what you wanted. I have updated my answer with a simple example of how you would go about this.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Its not working
For your better understanding i will explains further more details.
Two customfileds:
1.LOB (The three coustomfield values are None, PowerEdge, Extreme Scale Infrastructure and the default value set to None)
2.Platform Found (Its has list of values based on LOB values what i mean is , if i select PowerEdge it has to generate some list contains 111 values . similarly if i select Extreme Scale Infrastructure it has to generate 47 values . This values are coming from data base)
Platform found values are generated by my code, its is clearly working i seen that by putting log messages
Both the customfields(LOB,Platform Found) are on the same screen(create screen) . so i guess LOB is the on change event
import com.atlassian.jira.component.ComponentAccessor def platformFoundField = getFieldByName("Platform Found") def lobField = getFieldById(getFieldChanged()) def optionsManager = ComponentAccessor.getOptionsManager() def customFieldManager = ComponentAccessor.getCustomFieldManager() def customField = customFieldManager.getCustomFieldObject(platformFoundField.getFieldId()) def config = customField.getRelevantConfig(getIssueContext()) def options = optionsManager.getOptions(config) // If LOB field is AAA set other field to First value if (lobField.value == "PowerEdge") { def optionToSelect = options.find { it.value == "First" } platformFoundField.setFormValue(optionToSelect.optionId) } else { // Default to None if not AAA value platformFoundField.setFormValue(null) }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It sounds like you want to set default field values based on another field. So when LOB is changed to a particular value, steps to reproduce has some default values set?
Are you using some plugin to load the values from a database? Or you want to load them using ScriptRunner?
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.