Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Can I a set a behaviour to work when a user makes changes to fields on an edit/create form?



I'm trying to make some fields read-only/invisible on a create issue screen, depending on other values the user has selected on the form.

I can get behaviours to work when opening a form on an existing issue based on the value of a field that's already set. What I'm trying to achieve is dynamically showing fields (or setting values) based on a user's selection within that form.

As a simple example, on a Create Issue screen, say I present a user with two select fields. If and only if they pick particular options from them, I may want to prompt for more information in a third field.

How can I conditionally show them that third field on that condition without making them submit their values first?


N.B. I'm experimenting with the Dynamic Forms for Jira plugin at the moment, but I'd much rather do this in ScriptRunner if possible, because I'd expect it would offer much more control and functionality.



2 answers

1 accepted

Behaviours do work dynamically on the Create screen (and other screens in general). For example:

  • A user attempts to create an issue
  • They choose a Select List Value of "New"
  • A text field is automatically hidden based on that selection, without the need to submit the form

This is an example script of that:

def reqValF= getFieldById(getFieldChanged())
def depTxtF = getFieldById('customfield_10503')
def reqValF_val = reqValF.getValue() as String

if (reqValF_val != "New") {
} else {

There wouldn't be any additional effort required on your part to automatically hide the field and the user won't need to actually submit the form for it to work.

Thanks for responding Joshua!

I'm just discovering the joys of getFieldChanged at the moment; so far I've got it working on a single field.

Is there any way of getting it to track changes on more than one field at a time though?

The logic I'd like to implement is something like:

if (reqVal1_val == "Field1val1" && reqVal2_val == "Field2Val1")

I'm thinking something along the lines of putting a getFieldChanged() in each of the fields I'm tracking, passing the values to variables defined in the initializer, then calling a method defined in the initializer when either of the fields changed.

I'm probably barking up the wrong tree though as my field-level scripts aren't seeing the methods I'm defining in the initializer.

There's probably an obvious solution that I've not even thought of yet, or I'm just going wrong somewhere along the way.

Any suggestions?

What I've done now is added the following code to EACH field I want to track:


def makeChanges() {
 def f1 = getFieldByName("Field 1").getValue();
 def f2 = getFieldByName("Field 2").getValue();
    if(f1=="Value 1" && f2=="Value 2") {
     getFieldByName("Field 3").setHidden(true);
    } else {
     getFieldByName("Field 3").setHidden(falue);   



Works a treat for the most part!


The only thing I'm missing now is how to get the right value if Field 1 is a cascading select. I'll keep reading up, unless @Joshua Yamdogo _ Adaptavist has the answer up his sleeve :)


In any case, I'd say this question is answered, thanks Joshua

Hi Darren,

Using getValue() on a cascading select list field returns an array. To the value of either the parent or child option of a cascading select list, you'll just need to access the right index.

def cascadingSelect = getFieldById(getFieldChanged()) 
def cascadingArray = cascadingSelect.getValue()

log.debug("The values for the Cascading Select List are: " + cascadingArray)
log.debug("The first value is: " + cascadingArray[0])
log.debug("The second value is: " + cascadingArray[1])

Returns this for me:

The values for the Cascading Select List are: [BBB, B2]
The first value is: BBB
The second value is: B2  

You might get an error in the inline editor about "cannot find matching method getAt(int)." That's OK - it will still work.

Thanks for that Joshua,

Interrogating the individual array elements works perfectly.

Quick question on that first line of your log: does that still return an array, or is it another data type? See, I'm trying to query the cascading select field as a single string (to get something like if cascadingSelectValue == "Value1;Value2"). So I thought I'd write a function that receives a String[] parameter and returns a string, which concatenates cascadingArray[0] and cascadingArray[1].

Seem to be getting a class cast error when I do that though. Is there something I'm missing here?


Here's the code I've got so far:

def cascadingToString(String[] fieldValue, String delimiter=";#") {
    def outputString = "";
    outputString = fieldValue[0];
    if (fieldValue[1]){
        outputString += delimiter += fieldValue[1];
    return outputString;

You know what, I think we're good, actually. I'm just doing the test inline by concatenating each of the two elements at the point of the test.

I'm using:

comparisonString == (fieldValue[0] + ";#" + fieldValue[1])

and that works well enough for me for now.

Thanks @Joshua Yamdogo _ Adaptavist for your help on this! 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Confluence

An update on Confluence Cloud customer feedback – June 2022

Hi everyone, We’re always looking at how to improve Confluence and customer feedback plays an important role in making sure we're investing in the areas that will bring the most value to the most c...

174 views 1 3
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you