Forums

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

How do I control the visibility of one field based on other field value selection on create screen

murthy manjunath
Contributor
October 15, 2018

Hello Team,

 

I would need a suggestion here. How do I control the visibility of one field based on other field value selection on create screen.

 

Example:

 

I have a field in create screen named as "Additional Itinerary" which is checkbox field.

It has values say 1, 2, 3 4, 5

 

I also have fields in create screen named as "Amount", "Cash"

 

Now, If value in "Additional Itinerary" field is selected as "1", only then the field "Amount" should be displayed in Create screen.

 

 

How can I achieve this ?

 

I have script runner plugin with me, can we do it with script runner. Please advise ?

2 answers

0 votes
Alvin
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.
October 15, 2018

Hi @murthy manjunath , you can achieve this via Scriptrunner Behavior, I assume that you want it on customer portal because you say upon creation. I will give  you a sample code to start with.

def addItenerary = getFieldByName("Additional Itenerary")  // customfield name

def amount = getFieldByName("Amount") // amount field

def cash = getFieldByName("Cash") // cash field

def addValue = addItenerary.getValue()

if (addValue == 1) {

amount.setHidden(false)

cash.setHidden(true)

}

 

you can add more if else statement , depending on your needs.

 

Hope this helps

Alvin

murthy manjunath
Contributor
October 16, 2018

Hi Alvin,

 

Thank you for taking time to assist.

I tried your suggestion, but the fields are not hidden. Please see the screenshot below if i am doing it correct ?

 

"Additional Itinerary" is the field which has value called "Forex". If this value is selected only then the fields named "Forex Card Amount" and "Forex Cash" should be displayed, else these fields should not be displayed.

 

Behavior.jpg

 

Fields in create screen Screenshot:

Fields.jpg

 

Regards,

Murthy

Alvin
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.
October 16, 2018

Hi @murthy manjunath , put the code on the server side , not on the initialiser. select your custom field on Add Field , put Additional Itenerary then place the code

Hope that helps

Best Regards,
Alvin

murthy manjunath
Contributor
October 16, 2018

Hi Alvin,

 

Thank you, I put the script in server side script by choosing field Additional Itinerary. However, here is the problem i am noticing.

 

Moment I select the checkbox value as anything other than "Forex", the fields are hidden. Later if I check the checkbox "Forex" fields are still hidden and does not display.

 

Here is the condition I am looking for;

 

If checkbox value of "Additional Itinerary" field contains value "Forex", then the custom fields "Forex Card Amount", "Forex Cash", "Currency Requirement" should be displayed.

 

If "Forex" checkbox is not selected then it should stay hidden.

 

Screenshots of code an screens attached for reference.

 Script.jpgScreen with all fields.jpgScreen.jpg

Alvin
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.
October 16, 2018

Hi @murthy manjunath , do the else statement for the following scenarios. just follow the format, I didn't test it but it should work

murthy manjunath
Contributor
October 16, 2018

HI @Alvin

Did I miss anything from your previous comments, I do not see the scenarios as you have mentioned. Please assist.

 

Thank you

Alvin
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.
October 16, 2018

Hi @murthy manjunath , what I mean is  you do the else statement based on your scenario

 

else {

 anyfield.setHidden(true)

anyfield1.setHidden(true) 

}

like this

Suggest an answer

Log in or Sign up to answer