Show or Hide field based on component value

Lakshmi S March 30, 2020

Hi Team,

Requirement is , Display new field "Bundle Version" based on Component value "NetSuite"> I tried to accomplish this through behaviors plugin. When selected the "NetSuite" component, the bundle Version is not displaying on create screen. Did i miss anything in this script ? can anyone please help on this.

Below is the code i used.


def formComponent = getFieldByName("Component/s")
def formBundle = getFieldByName("Bundle Version")

def componentFieldValues = formComponent.getValue() as String


if (componentFieldValues.toString().contains("NetSuite"))
{
formBundle.setHidden(false)
formBundle.setRequired(true)
}
else
{
formBundle.setHidden(true)
formBundle.setRequired(false)
}

1 answer

1 accepted

0 votes
Answer accepted
C_ Derek Fields
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 30, 2020

Where did you put your behaviour? If it is in the screen Initializer, then it only executes the first time that the screen is shown. If you put it into the Component/s field, it will run each time Component/s is accessed. 

Lakshmi S March 30, 2020

Thanks for the quick reply @C_ Derek Fields , I have added "Bundle Version" field and added the script to server side scriptversion.PNG

C_ Derek Fields
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 30, 2020

You need to put this script on the Component/s field. You want the behavior to trigger when the component/s field is updated. That will then update the bundle version field.

Lakshmi S March 30, 2020

Hi @C_ Derek Fields ,

 Its not displayed. Is the code correct ? Please attached screenshot for your reference.

def formComponent = getFieldByName("Component/s")
def formBundle = getFieldByName("Bundle Version")

def componentFieldValues = formComponent.getValue() as String


if (componentFieldValues.toString().contains("NetSuite"))
{
formBundle.setHidden(false)
formBundle.setRequired(true)
}
else
{
formBundle.setHidden(true)
formBundle.setRequired(false)
}

code.PNG

C_ Derek Fields
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 30, 2020

The script isn't correct. This should work for you:

def formComponent = getFieldById(getFieldChanged())
def formBundle = getFieldByName("Bundle Version")

List componentFieldValues = formComponent.getValue().collect {it.getName()}

if ("NetSuite" in componentFieldValues)
{
formBundle.setHidden(false)
formBundle.setRequired(true)
}
else
{
formBundle.setHidden(true)
formBundle.setRequired(false)
}
Lakshmi S March 31, 2020

Hi @C_ Derek Fields ,

 Perfect. Its working as expected. Thank you so much for your quick response Derek.  For this line its showing error like "Cann't find matching method etc", but we can ignore that error.

List componentFieldValues = formComponent.getValue().collect {it.getName()}

  buildv.PNG

Suggest an answer

Log in or Sign up to answer