how to make all variables setDisplay false in a variable set in client script ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2023 12:51 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2023 01:00 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2023 03:17 AM
@Mohan raj There are some fields which I'm making read only will they be caputred here and hidden?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2023 04:23 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2023 04:33 AM
@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.