Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSS

get variable containers

//init
var CATALOG_ITEM_SYS_ID = '', //TODO: REPLACE THIS WITH THE SYS_ID OF THE CATALOG ITEM
    i,
    currentVar,
    fieldName = 'sys_id',
    varMap = {},
    currentContainer,
    containerLevel = [],
    item = GlideappCatalogItem.get(CATALOG_ITEM_SYS_ID),
    grVariables = item.getVariables();

//For every variable found...
while (grVariables.next()) {

    var varName = grVariables.getValue('name');
    var varSid = grVariables.getValue('sys_id');
    var varType = grVariables.type.getDisplayValue();
    var varQuestion = grVariables.getValue('question_text');
    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;
}
Source by snprotips.com #
 
PREVIOUS NEXT
Tagged: #variable #containers
ADD COMMENT
Topic
Name
1+1 =