Is there anyway to query whether a variable set exists on a catalog item/record producer using a client script (g_form)

Jon Crosby
Tera Expert

Is there anyway to query whether a variable set exists on a catalog item/record producer using a client script (g_form)?

2 REPLIES 2

Michael Jones -
Giga Sage

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!

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

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