Dynamically populating text field based on selection

I have been experimenting with the Behaviours plugin in JIRA.

I have been successful with many scripts, but I am not able to figure this one out. I want to be able to insert text into a custom text field, if a certain selection is chosen from a select field.

Here is my code:


import com.atlassian.jira.component.ComponentAccessor

import static com.atlassian.jira.issue.IssueFieldConstants.*


// Get pointers to the custom field(s) required

def cf = getFieldByName("Custom Select list field A")

def cf1 = getFieldByName("Custom text field B")


// Get the Value of Custom Field A

def cfVal = cf.getValue().toString()


if (getActionName() != "Create Issue") {

    return // not the initial action, so don't set default values


if (cfVal == "Selection from Select List"){

   cf1.setFormValue("Default text I want to have input")




I was attempting to follow https://scriptrunner.adaptavist.com/4.3.0/jira/recipes/behaviours/setting-default-fields.html as closely as possible, but can't seem to get it to work.


Any help is greatly appreciated!



1 answer

1 accepted

Hi Nick,

I have attached a sample script below which shows how you can add some default text to a multi line text field when a certain option is selected in a text field and remove the text once the option in the select list field is changed.

// Get pointers to my fields
def textField = getFieldByName("DemoTextFieldMultiLine")
def selectList = getFieldByName("DemoSelectList")

// Get the Value of my Select Field
def selectListVal = selectList.getValue()

// Specify my default text
String defaultText = "This my default text to add to my multi line text field."

// If the Select List Value matches the option A then set some default Text
if(selectListVal.toString() == "A"){
// If the select Field value is unselected or a different match then clear the default text

Also if you want to restrict this behaviour to only apply on the create or edit screens then you can do this by Simply adding the workflow used as a Guided Workflow to your behaviours and add a condition to specify when this behaviour should fire.

I have attached a screenshot below which shows how to restrict this behaviour to the edit screen but this could easily be modified to only allow the behaviour to fire on the create screen.

Screen Shot 2016-10-05 at 12.01.38.png

I hope this helps.



Suggest an answer

Log in or Sign up to answer
Community showcase
Published Feb 07, 2019 in Marketplace Apps

A Timeless Love Story

It started as any story starts, on a normal, rainy day.   Admin meets App, and her name was Klok2, and like any first relationship we were both trying to make it work but neither one knew what...

442 views 8 26
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