Hide field using client script in user tabke

Govind Bysani
Tera Contributor

In my user table, I have created a section called 'Additional details', In that section I have 5 fields in it, I need to hide 2 of those 5 fields using client script. Can anyone help me on this.

1 ACCEPTED SOLUTION

Robbie
Kilo Patron
Kilo Patron

Hi @Govind Bysani,

 

As you've specifically asked to hide the fields via a Client Script, leverage the g_form.setDisplay() method as shown within an onLoad Script: (Obviously you'll want to write the appropriate clause/syntax as to when to hide or not)

 

g_form.setDisplay('the_field_name_to_hide', false); //Enter the field name to hide within quotes

 

Please note, based on the execution order and call stack, best practice guides you to use a UI Policy.

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.

 

Thanks, Robbie

View solution in original post

2 REPLIES 2

Maddysunil
Kilo Sage

@Govind Bysani 

Please use below sample script and modify accordingly:

 

var field1 = g_form.getControl('field1_sys_id'); // Replace 'field1_sys_id' with the actual sys_id of your field
    var field2 = g_form.getControl('field2_sys_id'); // Replace 'field2_sys_id' with the actual sys_id of your field

    // Check if both fields exist
    if (field1 && field2) {
        // Hide the fields
        field1.style.display = 'none';
        field2.style.display = 'none';

        // Optionally, you can also hide the labels if needed
        var label1 = g_form.getLabelOf(field1);
        var label2 = g_form.getLabelOf(field2);
        if (label1) {
            label1.style.display = 'none';
        }
        if (label2) {
            label2.style.display = 'none';
        }
    }

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

Robbie
Kilo Patron
Kilo Patron

Hi @Govind Bysani,

 

As you've specifically asked to hide the fields via a Client Script, leverage the g_form.setDisplay() method as shown within an onLoad Script: (Obviously you'll want to write the appropriate clause/syntax as to when to hide or not)

 

g_form.setDisplay('the_field_name_to_hide', false); //Enter the field name to hide within quotes

 

Please note, based on the execution order and call stack, best practice guides you to use a UI Policy.

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.

 

Thanks, Robbie