Trigger the evaluation of a behaviour field from another behavior field

Daniel Morris January 28, 2021

Hi,

I've got an issue (and not the first time i've run into it actually) that i find myself needing to get another field on the same form as a field to re-evaluate the behaviour script attached to it. 

My exact scenario is say you have 3 fields which all have values that rely on each other (Like a cascading select) and i want achieve the following:

  1. Make field 2 and 3 read only when the 1st field has no value selected
  2. Make the 3rd field read only when the 2nd field has no value selected.  

In my mind it seems to me that you would want to keep the logic for making a field read only in it's parent script so field 1's state determines if field 2 should be read only and field 2's state determines if field 3 should be read only.

That is achievable without having the scripts be interdependent but it does require each script to be setting the state of all other fields involved when it's value changes (so in bullet 1 above the script on field 1 is having to set the read only state of 2 and 3). It would easier if a field could trigger the re-evaluation of another field in the chain. Is there any way to achieve this other than just having each of the scripts set the state for all of them (or at least fields 'below' it in the chain).

Thanks in advance.

1 answer

0 votes
Ram Kumar Aravindakshan _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.
March 28, 2021

Hi Daniel,

For your requirement, you will need to make two behaviour configurations for Field 1 and Field 2.

If Field 1 is selected,  Field 2 becomes editable, and if the value is selected from Field 2, only then will Field 3 become editable.  This code has also got to be added for the Field 2 behaviour in a different order.

Below is the behaviour code for Field 1:

def list1 = getFieldById(fieldChanged)
def list1Value = list1.value.toString()

def list2 = getFieldByName("List 2")
def list2Value = list2.value.toString()

def list3 = getFieldByName("List 3")

list2.setReadOnly(true)
list3.setReadOnly(true)

if(list1Value != "null" && list2Value!="null") {
list2.setReadOnly(false)
list3.setReadOnly(false)
} else if(list1Value != "null" && list2Value == "null") {
list2.setReadOnly(false)
}

and below is the behaviour code for Field 2:

def list2 = getFieldById(fieldChanged)
def list2Value = list2.value.toString()

def list1 = getFieldByName("List 1")
def list1Value = list1.value.toString()

def list3 = getFieldByName("List 3")

list2.setReadOnly(true)
list3.setReadOnly(true)

if(list2Value!="null" && list1Value != "null") {
list2.setReadOnly(false)
list3.setReadOnly(false)
} else if(list2Value == "null" && list1Value != "null") {
list2.setReadOnly(false)
}

Please note, this sample code is not 100% exact to your environment. Hence, you will need to make the required modifications.

Below is a print screen of the Behaviour configuration for your reference:-

behaviour_config.png

I hope this helps to solve your question. :)

 

Thank you and Kind regards,

Ram

Suggest an answer

Log in or Sign up to answer