I have two strings how to change

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 vote

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

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.

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

 

 

 

 

 

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?

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

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published yesterday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

60 views 0 3
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you