Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Show or Hide field based on component value

Lakshmi CH
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

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
Derek Fields (RightStar)
Community Champion
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 CH
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

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

Derek Fields (RightStar)
Community Champion
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 CH
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

Hi @Derek Fields (RightStar) ,

 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

Derek Fields (RightStar)
Community Champion
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 CH
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 31, 2020

Hi @Derek Fields (RightStar) ,

 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