How to check if the field is visible on the form in catalog client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2021 11:31 AM
Hi All,
Does anyone know how to find if the variable is present on the form in catalog client script?
Thanks In Advance
Vidyashree
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2021 11:57 AM
Hi,
Please see this thread for details: https://community.servicenow.com/community?id=community_question&sys_id=7f132caadb76d4d011762183ca96...
g_form.isVisible('field')
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2021 12:10 PM
Hello Vidya,
What I can understand from your question is that, you are looking for how a variable name field appears on the catalog client script form or if we select any variable set then a particular variable is made available in the variable name field. If so, then the solution could be:
- In the catalog client script form, opt for variable set in the field Applies to
- then select type of client script as onChange (the variable name field will appear on selecting onChange, as this catalog client script will work on change of a particular field value)
- Select the variable set of your requirement, and thus all the related variables will appear in the variable name field.
Please to the following snapshot of above explained steps:
And now if your requirement is to check if any field is hidden/visible on the form, for this you can write a simple script in the catalog client script and can select the type as onLoad. Use the following script:
if(g_form.isVisible('fieldName')) {
alert('is visible');
}
else {
alert('is hidden');
}
If you find the above solution appropriate, then please mark the answer Correct/Helpful.
Regards,
Soumya

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2021 12:15 PM
It is unclear what you are asking for. Your title indicates a field whereas your body indicates a variable. There is a g_form method called hasField() which allows you to see if a field is available on a table view. This can be helpful if you want to see if a field you need is available on the form: g_form.hasField('field_name');
When you are on the request form you can still use the same method, but it is unclear why you would if you are designing the form to have the variable you are looking for. Please let us know the business need for having to find a variable and exactly where you are looking for it (request form, requested item table, catalog task table)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2023 10:24 AM
In case people need something on this, I came up with :
g_form.isFieldVisible('your_field_name') on the back office.
this.document.getElementsByName('your_field_name').item(0).checkVisibility() on service portal.
These return 'true' or 'false'.