Client Script - Onload to hide/show fields based on the data

John Prouty
Kilo Guru

i have successfully coded OnChange client scripts to show and hide various fields on the form, but now I need to have those fields shown/hidden when the form opens and the record already has data.

I coded a OnLoad script, but it doesn't seem to even fire (I put an addErrorMessage('HI'); just to see if it starts.  The message does not appear.  How do I code the Client Script so that it fires when the form is opened and before any data is changed.

Here is part of the script I have written

find_real_file.png

1 ACCEPTED SOLUTION

Willem
Giga Sage
Giga Sage

Hi John,

Change line 2 from:

find_real_file.png

 

To:

var RouterType = g_form.getValue('router_type');

Make sure the names are the correct (technical) names of the field as well.

 

In addition, change linke 8:

find_real_file.png

 

To:

RouterType == ''

View solution in original post

3 REPLIES 3

John Prouty
Kilo Guru

I took the two getValue method call out and the message appeared.  When I put them back in, the CS does not run.  So the issue is "how do I access data in an OnLoad CS?"  One thread said to use getDisplayBox, but it returns "undefined" as the value and the record I am looking at has data.  This should be fairly standard functionality for SN.  If I open up a form created by a Record Producer, I want to hide and show fields based on the values that the requestor specified in the Catalog.

Willem
Giga Sage
Giga Sage

Hi John,

use: g_form.getValue() instead

Willem
Giga Sage
Giga Sage

Hi John,

Change line 2 from:

find_real_file.png

 

To:

var RouterType = g_form.getValue('router_type');

Make sure the names are the correct (technical) names of the field as well.

 

In addition, change linke 8:

find_real_file.png

 

To:

RouterType == ''