Is there anyway to query whether a variable set exists on a catalog item/record producer using a client script (g_form)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-26-2021 10:23 AM
Is there anyway to query whether a variable set exists on a catalog item/record producer using a client script (g_form)?
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-26-2021 02:14 PM
You can check whether a variable set exists using g_form.hasField(). It will return true if the variable set is on the form and false if not. You would supply the internal name of the variable set. For example, if I have a variable set with an internal name of additional_data I could use an onload script like this to check whether it exists on the item. Works in both the native UI and the Service Portal:
function onLoad() {
//will alert true or false
alert(g_form.hasField('additional_data'));
}
I hope this helps!
If this was helpful or correct, please be kind and remember to click appropriately!
Michael Jones - Proud member of the CloudPires team!
Michael D. Jones
Proud member of the GlideFast Consulting Team!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-27-2021 07:17 AM
Thanks Mike.
I tested this and cannot get it to work with variables - it doesn't find them.
GetValue can find variables, but it returns the same value whether the variable set does or doesn't exist.
https://community.servicenow.com/community?id=community_question&sys_id=d71d8f69db9cdbc01dcaf3231f96191b