- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2016 08:38 AM
I have this simple onSubmit script to check to see if the user entered at least 12 digits into a field. The problem is, this field isn't always shown on the catalog item. The mac_address field only appears (and becomes mandatory) if another field is set to X.
I was looking in the scripting wiki and saw the g_form.setVisible, but I'm not sure if I can use that in this case.
I tried adding if (g_form.setVisible('mac_address', true)) { but that just made the entire script fail.
function onSubmit() {
//Type appropriate comment here, and begin script below
if
var mac = g_form.getValue('mac_address');
if (mac.toString().length < 12) { // or whatever number you want
g_form.setValue('mac_address','');
alert('Please enter the full 12 digit MAC address.');
}
}
Thanks!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2016 08:43 AM
You can check to see if the field is mandatory or not, but not whether it is displayed/visisble.
g_form.isMandatory(fieldName) will return true or false.
Since you cannot hide a mandatory field (at least with UI policies) you can tell whether or not the field is visible or not.
GlideForm (g form) - ServiceNow Wiki
There may be a way to do it with g_form.getControl(), but I haven't dug in to the returned HTMLElement to know what you get back.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2016 08:55 AM
Hi Alexander,
Could you please elaborate your requirement with more clarity? What actually is the requirement? I mean to say when do you want to see the particular field and when not.
Thanks,
Arnab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2016 09:41 AM
Hey Arnab, Chuck was able to point me in the right direction but thanks for your reply.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2018 01:05 AM
There is a solution, see here:
https://community.servicenow.com/community?id=community_question&sys_id=e3f98f29db5cdbc01dcaf3231f9619c4
If this answer was helpful, I would appreciate if you marked it as such - thanks!
Best
Daniel