I have two strings how to change

Rukyam96 June 30, 2016

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 

1 answer

0 votes
adammarkham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 30, 2016

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 

Rukyam96 June 30, 2016
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). 

adammarkham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 30, 2016

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.

Rukyam96 June 30, 2016

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 

for this i am trying this code:

 

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)
}

 

 

 

 

 

adammarkham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 30, 2016

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?

Rukyam96 June 30, 2016

yes, i am using different plugin to load values into data base

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events