logo

NJP

Get all variables for a given catalog item

Import · Aug 10, 2016 · article

Catalog Variables are stored in a table item_option_new.

The variables are associated either to a catalog item or to a variable set.

The association between catalog item and variable set is stored in io_set_item.

Create a Database view on the two tables like this

image

Expose the following fields in each table

Table: item_option_new

image

Table: io_set_item

image

Note the whereclause.

Try the database view and have the following filter and list layout. (Note: The two Catalog Item comes from the different tables in the view)

image

Note: Multi Row Variable Set Values cant be achieved by this method

Another solution is to get it via query. Here is a simple query to do the same.

https://docs.servicenow.com/bundle/madrid-application-development/page/script/server-scripting/conce...

var gr = new GlideRecord('sc_req_item'); 
if (gr.get('635a1f5387320300e0ef0cf888cb0b73')) { 
    var variables = gr.variables.getElements(); 
    for (var i=0;i<variables.length;i++) { 
        var question = variables[i].getQuestion(); 
        gs.log(question.getLabel() + ":" + question.getValue()) 
    } 
}

From New York to get values of table variable

var gr = new GlideRecord('sc_req_item');
gr.get('02c38dcd87013300e0ef0cf888cb0bb2');

var vars = gr.variables.getElements(true); //Get Table Variables as well

for (var i=0; i<vars.length; i++) {
    var v = vars[i];
    if (v.isMultiRow()) {
        var rows = v.getRows();
        for (var j=0; j<v.getRowCount(); j++) {
            var row = rows[j];
            var cells = row.getCells();
            for (var k=0; k<cells.length; k++) {
                var cell = cells[k];
                gs.info(cell.getLabel() + ":" + cell.getCellDisplayValue())
            }
        }
    }
}
View original source

https://www.servicenow.com/community/now-platform-blog/get-all-variables-for-a-given-catalog-item/ba-p/2289408