Name
global.PPMConsole
Description
No description available
Script
var PPMConsole = Class.create();
PPMConsole.prototype = {
initialize: function(tableName, context) {
this.tableName = tableName;
this.context = context;
this.gr = undefined;
},
getConsole: function() {
this.gr = new GlideRecord("pm_console");
this.gr.addQuery("table", this.tableName);
if(JSUtil.notNil(this.context))
this.gr.addQuery("context", this.context);
this.gr.query();
if(this.gr.next())
return this.gr;
},
isValid: function () {
var console = this.getConsole();
if(JSUtil.notNil(console))
return true;
return false;
},
getChildTables: function () {
PPMDebug.log("Into PPMConsole.getChildTables...");
var childTables = [];
if(JSUtil.notNil(this.gr.getValue("child_tables"))) {
var childTableIds = this.gr.getValue("child_tables");
childTables = this.getChildTableNames(childTableIds);
}
return childTables;
},
getChildTableNames: function (tableIds) {
PPMDebug.log("Into PPMConsole.getChildTableNames -> " + tableIds);
var tableNames = [];
if(JSUtil.notNil(tableIds)) {
var grTable = new GlideRecord("sys_db_obejct");
grTable.addQuery("sys_id", "IN", tableIds);
grTable.query();
while(grTable.next()) {
tableNames.push(grTable.getValue("name"));
}
}
PPMDebug.log("Into PPMConsole.getChildTableNames -> " + tableNames.join(","));
return tableNames;
},
getTables : function() {
var tables = [];
var console = new GlideRecord('pm_console');
console.addQuery('entity', this.tableName);
if(JSUtil.notNil(this.context))
console.addQuery("context", this.context);
console.query();
if ( console.next() ) {
var consoleTables = new GlideRecord('pm_console_table');
consoleTables.addQuery('pm_console', console.getValue('sys_id'));
consoleTables.query();
while ( consoleTables.next() ) {
tables.push(consoleTables.getValue('table'));
}
}
return tables;
},
getJSONColumnForColumn: function (column) {
PPMDebug.log("Into PPMConsole.getJSONColumnForColumn -> " + column);
if(this.isValid()) {
var grC = new GlideRecord("pm_console_column");
grC.addQuery("column", column);
var joinQuery = grC.addJoinQuery("pm_console_table", "pm_console_table", "sys_id");
joinQuery.addCondition("pm_console", this.gr.getValue("sys_id"));
grC.addNotNullQuery("pm_console_display_column");
grC.query();
PPMDebug.log("getJSONColumnForColumn -> " + grC.getRowCount() + " | " + grC.getEncodedQuery());
if(grC.next()) {
return grC.pm_console_display_column.getRefRecord().getValue("json_column");
}
}
return column;
},
getTableDefaultValues: function (tableName) {
PPMDebug.log("Into PPMConsole.getTableDefaultValues -> " + tableName);
var defaultValues = {};
if(this.isValid()) {
var grT = new GlideRecord("pm_console_table");
grT.addQuery("pm_console", this.gr.getValue("sys_id"));
if(JSUtil.notNil(tableName)) {
grT.addQuery("table", tableName);
} else { // pick the first child table - ideally should be only one
grT.addQuery("table", "!=", this.tableName);
}
grT.query();
if(grT.next()) {
var tableDescriptor = new GlideTableDescriptor(grT.getValue("table"));
var grC = new GlideRecord("pm_console_column");
grC.addQuery("pm_console_table", grT.getValue("sys_id"));
grC.query();
while(grC.next()) {
var columnName = grC.getValue("column");
if(JSUtil.notNil(columnName)) {
var elementDescriptor = tableDescriptor.getElementDescriptor(columnName);
var defaultValue = '';
if(elementDescriptor) defaultValue=elementDescriptor.getDefault();
if(JSUtil.notNil(defaultValue) && defaultValue.indexOf('javascript') == -1) {
var jsonColumn = grC.pm_console_display_column.getRefRecord().getValue("json_column");
defaultValues[jsonColumn] = defaultValue;
PPMDebug.log("Getting displayValues -> " + tableName + " | " + columnName);
var choiceList = GlideChoiceList.getChoiceList(tableName, columnName);
var label = choiceList.getLabelOf(defaultValue);
if(JSUtil.notNil(label))
defaultValues["dv_" + jsonColumn] = label;
}
}
}
}
}
return defaultValues;
},
getTableColors: function (tableName) {
var tables = this.getTables();
var colors = {}, preferenceName, colorValue;
if(tables && tables.length > 0) {
for (var i = 0; i < tables.length; i++) {
preferenceName = "com.snc.project_management." + tables[i] + ".color";
colorValue = gs.getUser().getPreference(preferenceName);
if(JSUtil.notNil(colorValue)) {
colors[tables[i]] = colorValue;
} else {
colors[tables[i]] = "218ad8"; // default color
}
}
}
return colors;
},
isPlanningOnClient: function() {
var planningOnClient = false;
if(this.isValid())
planningOnClient = this.gr.getValue('enable_client_side');
return (planningOnClient == 'true' || planningOnClient == true);
},
type: 'PPMConsole'
};
Sys ID
013093eb37102200277826877e41f1b9