how to make all variables setDisplay false in a variable set in client script ?

Akki1
Tera Contributor

I want to make all variables in a variable set setDisplay false or true in a condition in client script  except one variable  in servicenow?

 

8 REPLIES 8

Mohan raj
Mega Sage

Hi @Akki1 ,

 

Try this 

var fields = g_form.getEditableFields();
for (var x = 0; x < fields.length; x++) {
        g_form.setDisplay(fields[x], false);
}

If my response helps you to resolve the issue close the question by Accepting solution and hit thumb icon. From Correct answers others will get benefited in future.

 

Regards

Mohan

 

Akki1
Tera Contributor

@Mohan raj  There are some fields which I'm making read only will they be caputred here and hidden?

Hi @Akki1,

yes g_form.setDisplay() will hide all fields in catalog if you want to skip some field then use below script.

var fields = g_form.getEditableFields();
var skipFields = ['last_name', 'first_name'] //mention variable name to skip then


for (var x = 0; x < fields.length; x++) {
var field = fields[x];
if(skipFields.indexOf(field) !== -1){
continue;
}
        g_form.setReadOnly(fields[x], true);
}

 

If my response helps you to resolve the issue close the question by Accepting solution and hit thumb icon. From Correct answers others will get benefited in future.

 

Regards

Mohan

 

Akki1
Tera Contributor

@Mohan raj The script doesn't run correctly.

getEditable fields doesn't get the all the fields . If I make the field read only in other script it doesn't fetch that field.