Catalog item variable type - How to identify?

AnttiTapiola
Tera Contributor

Hello Experts,

 

I would like to detect sc_cat_item variable type used in existing ritm tickets, but wondering how to do it. Usage of .getInternalType returns as example "com.glide.vars2.Variable" but not type like Single Line Text. 

 

Is there any way to return variable Type info?

while (grReqItem.next()) {
    var variables = grReqItem.variables;
    for (var variableName in variables) {
        var elementDescriptor = grReqItem.variables[variableName].getED();
        gs.info('Setting variable: ' + elementDescriptor + ' type:' + elementDescriptor.getInternalType() + ' value: ' + grReqItem.variables[variableName]);
    }
}

 

1 ACCEPTED SOLUTION

Sagar Pagar
Tera Patron

Hi @AnttiTapiola,

 

I would suggest to get the Catalog item using RITM requests.

Once you get the Catalog item, you need to Glide Variables [item_option_new] table and query with catalog item and you will get the variable typos.

 

If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers.
Thanks,
Sagar Pagar

The world works with ServiceNow

View solution in original post

4 REPLIES 4

Fabian Kunzke
Kilo Sage
Kilo Sage

Hey,

for variables there is a many-to-many table which links the variable to their request item:
sc_item_option_mtom

There you can filter for your request item. This will give you all references to the sc_item_option table which stores the instance of a variable with it's value. This then references the catalog variable itself. And there you then find the type of variable.

 

In case of any further input needed, feel free to respond.

 

Regards

Fabian

Sagar Pagar
Tera Patron

Hi @AnttiTapiola,

 

I would suggest to get the Catalog item using RITM requests.

Once you get the Catalog item, you need to Glide Variables [item_option_new] table and query with catalog item and you will get the variable typos.

 

If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers.
Thanks,
Sagar Pagar

The world works with ServiceNow

Hello,

This is an easy and great solution! However, please keep in mind, that if a catalog item changes over time to a new version with different variables, the variables of a request item may no longer match with the variables of the catalog item. Variables could be missing or be replaced/updated.

Regards

Fabian

D_vid Novotn_
Tera Contributor

I needed to check if variable is checkbox and if it is, then return its label.

Use current.variables.var_name.getQuestion().getType() to get the variable type

 

var checkboxType = '7';
var varName = <<var_name>>;
var label = '';
var current = new GlideRecord("sc_req_item");
if (current.get(<<sys_id>>)){
	var myVar = current.variables[varName];
	var isBoolean = myVar.getQuestion().getType() == checkboxType;
	if (isBoolean){
		label = myVar.getLabel();
	}
}