Table of Contents
1. Get Catalog Item Variables (Organized Into Containers)
#+beginsrc js //init var CATALOGITEMSYSID = '', //TODO: REPLACE THIS WITH THE SYSID OF THE CATALOG ITEM i, currentVar, fieldName = 'sysid', varMap = {}, currentContainer, containerLevel = [], item = GlideappCatalogItem.get(CATALOGITEMSYSID), grVariables = item.getVariables();
//For every variable found… while (grVariables.next()) {
var varName = grVariables.getValue('name'); var varSid = grVariables.getValue('sysid'); var varType = grVariables.type.getDisplayValue(); var varQuestion = grVariables.getValue('questiontext'); var varActive = grVariables.getValue('active');
if (varType =
'Container Start') {
containerLevel.push(varSid);
} else if (varType =
'Container End') {
containerLevel.pop();
}
currentContainer = varMap;
for (i = 0; i < containerLevel.length; i++) {
if (!currentContainer.hasOwnProperty(containerLevel[i])) {
currentContainer[containerLevel[i]] = {};
}
currentContainer = currentContainer[containerLevel[i]];
}
currentContainer[varSid] = new Variable(varName, varSid, varType, varQuestion, varActive); }
gs.print(JSON.stringify(varMap));
function Variable(varName, varSid, varType, varQuestion, varActive, varOrder) { this.varName = varName; this.varSid = varSid; this.varType = varType; this.varQuestion = varQuestion; this.varActive = varActive; this.varOrder = varOrder; } #+endsrc>