- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2016 09:38 AM
Hi,
I need to check a variable in a catalog client script onSubmit(). If the variable is visible, I need to check it. If it is not visible, the script does nothing.
So I need to access to the visibility of the variable, I thought about document.getElementById("IO:2bff02ec51ed21002b74916df91c253b").style.visibility or style.display.
But to get the status, I need to set it before... visibility or display returns nothing if I don't set it before (which is not what I need).
Any idea on how to get the visilibility (true / false) of a variable ?
Thanks.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2016 04:02 PM
EDIT: I think the following function will be what you're looking for.
just call this in your client script and you should be good to go. I've only tested this in a few scenarios and directly on the catalog item, haven't looked at a submitted form yet or anything along those lines. I'll try and update if I end up doing any more work on this.
function isVisible(fieldName) {
//This script does appear to return undefined if the variable name isn't present
var field = fieldName;
var id = g_form.resolveNameMap(field); //This will return IO:sys_id
var clean = g_form._cleanupName(field); //this should return just the sys_id variable
var nidot = gel('ni.' + id); //checkbox variables are hidden on this element.
var ctrl = g_form.getControl(id); //not used in this script, but get's the prototypeJS elemnt
var container = gel('container_' + clean); //getting the element for a container, one we actually don't have to crawl for parent nodes or anything along those lines
var label = gel('label_' + id); //This should be all other field types. (testing was limited to single/multi line text, reference, and list collector) mileage may vary
if (container) {
return container.visible();
}
if (nidot) {
return nidot.parentNode.visible();
}
if (label) {
if (hasClassName(label, 'io_label_container')) {
return label.visible();
} else {
return label.up(1).visible(); //same as label.parentNode.parentNode.visible(), just shorthand.
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2016 11:18 AM
Have you tried g_form.isSectionVisible?
http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)#isSectionVisible
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2016 11:44 AM
Well, I can't because it's starting from Fuji and we are on Eureka instance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2016 04:26 PM
Couldn't you check the variables for the conditions in your UI Policy and Client Scripts that are making the checkbox visible in the first place and use them as the condition in this client script as well?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2016 04:02 PM
EDIT: I think the following function will be what you're looking for.
just call this in your client script and you should be good to go. I've only tested this in a few scenarios and directly on the catalog item, haven't looked at a submitted form yet or anything along those lines. I'll try and update if I end up doing any more work on this.
function isVisible(fieldName) {
//This script does appear to return undefined if the variable name isn't present
var field = fieldName;
var id = g_form.resolveNameMap(field); //This will return IO:sys_id
var clean = g_form._cleanupName(field); //this should return just the sys_id variable
var nidot = gel('ni.' + id); //checkbox variables are hidden on this element.
var ctrl = g_form.getControl(id); //not used in this script, but get's the prototypeJS elemnt
var container = gel('container_' + clean); //getting the element for a container, one we actually don't have to crawl for parent nodes or anything along those lines
var label = gel('label_' + id); //This should be all other field types. (testing was limited to single/multi line text, reference, and list collector) mileage may vary
if (container) {
return container.visible();
}
if (nidot) {
return nidot.parentNode.visible();
}
if (label) {
if (hasClassName(label, 'io_label_container')) {
return label.visible();
} else {
return label.up(1).visible(); //same as label.parentNode.parentNode.visible(), just shorthand.
}
}
}