ScriptRunner Behavior: fill Field option based on another Field option

Timothy Ryner June 26, 2020

Total scriptrunner noob!

I have two dropdown fields that I am attempting to tie together one the create/edit screens.  The idea is to allow a user to pick an option in either field, and the other field will populate immediately with the appropriate value.  

Fields:

  • SWID Name
    • one one one
    • two two two
    • three three three
  • SWID #
    • 111
    • 222
    • 333

If / Then:

  1. If user selects SWID Name == "one one one
    then set SWID # == "111"
  2. If user selects SWID Name == "two two two
    then set SWID # == "222"
  3. If user selects SWID Name == "three three three" 
    then set SWID # == "333"
  4. If user selects SWID # == "111
    then set SWID Name == "one one one"
  5. If user selects SWID # == "222
    then set SWID Name == "two two two"
  6. If user selects SWID # == "333
    then set SWID Name == "three three three"

My script so far is just an attempt to get something super simple to work.  Once I have the basic recipe, I'll build it up from there.  

import com.atlassian.jira.issue.IssueInputParameters
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import com.atlassian.jira.component.ComponentAccessor

@BaseScript FieldBehaviours fieldBehaviours

def SWIDNumField = getFieldById(getFieldChanged())
String SWIDNumOption = SWIDNumField.getValue()
def SWIDNameField = getFieldByName("SWID Name")


if (SWIDNumOption == "111" )
{ SWIDNameField.setFormValue("one one one")
}

else if (SWIDNumOption == ("222") )
{ SWIDNameField.setFormValue("two two two")
}

else if (SWIDNumOption == ("333") )
{ SWIDNameField.setFormValue("three three three")
}

else
{
SWIDNameField.setFormValue("None")
}

 Any help is greatly appreciated!

I have not found a good way of learning Groovy, besides attempting to solve problems like this.  If there is a good course out there to logically learn how to groovy, I'm open learning and solving this on my own.

1 answer

1 accepted

3 votes
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 28, 2020

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events