Name
global.ProjectData
Description
Project Data for Project Diagnosis
Script
var ProjectData = Class.create();
ProjectData.prototype = {
initialize: function(taskId) {
this.topTaskId = taskId;
this.tasks = [];
this.tasksObject = {};
this.relations = [];
this.relationsObject = {};
this.relationTypes = {};
this.schedule = '';
this.validateAndLoad(taskId);
this.tasksObject['sys_ids'] = this.tasks;
this.relationsObject['sys_ids'] = this.relations;
},
validateAndLoad: function(taskId) {
var gr = new GlideRecord('pm_project');
gr.get(this.topTaskId);
if ( JSUtil.nil(gr.getValue('schedule')) )
this.schedule = 'No schedule';
else
this.schedule = gr.getDisplayValue('schedule');
gr = new GlideRecord("planned_task");
if(JSUtil.notNil(taskId) && gr.get(taskId)) {
if(JSUtil.notNil(gr.getValue('top_task'))) {
this.topTaskId = gr.getValue("top_task");
if(this.topTaskId != taskId) {
gr.get(this.topTaskId);
}
}
this.topPortfolioId = gr.getValue('top_portfolio');
this.topProgramId = gr.getValue('top_program');
this.tasks.push(this.topTaskId);
this.tasksObject[gr.getValue("sys_id")] = this.getTaskObject(gr);
this.loadAllTasks();
this.loadAllRelations();
}
},
loadAllTasks: function() {
var count = 0;
while(count < this.tasks.length) {
var taskId = this.tasks[count];
this.loadTasks(taskId, '^parent='+taskId);
count += 1;
}
PPMDebug.log('All Tasks -> ' + this.tasks.length + " -> " + this.tasks.join(','));
},
loadAllRelations: function() {
var count = 0;
this.loadRelations('^parentIN'+ this.tasks.join(',') + "^ORchildIN" + this.tasks.join(','));
PPMDebug.log('All Relations -> ' + this.relations.length + " -> " + this.relations.join(','));
},
loadTasks: function(taskId, encodedQuery) {
var gr = new GlideRecord("planned_task");
gr.addEncodedQuery(encodedQuery);
gr.query();
PPMDebug.log("Tasks -> " + gr.getRowCount() + " -> " + gr.getEncodedQuery());
while(gr.next()) {
this.tasks.push(gr.getValue("sys_id"));
this.tasksObject[gr.getValue("sys_id")] = this.getTaskObject(gr);
}
},
getSchedule: function() {
return this.schedule;
},
getTaskObject: function (gr) {
return {
sys_id: gr.getValue("sys_id"),
number: gr.getValue("number"),
short_description: gr.getValue("short_description"),
parent: gr.getValue("parent"),
top_task: gr.getValue("top_task"),
start_date: gr.getValue("start_date"),
end_date: gr.getValue("end_date"),
duration: gr.getValue("duration"),
work_start: gr.getValue("work_start"),
work_end: gr.getValue("work_end"),
work_duration: gr.getValue("work_duration"),
state: gr.getValue("state"),
percent_complete: gr.getValue("percent_complete"),
top_portfolio: gr.getValue('top_portfolio'),
top_program: gr.getValue('top_program'),
top_portfolio_dv: gr.getDisplayValue('top_portfolio'),
top_program_dv: gr.getDisplayValue('top_program')
};
},
loadRelations: function(encodedQuery) {
var gr = new GlideRecord('planned_task_rel_planned_task');
gr.addEncodedQuery(encodedQuery);
gr.query();
PPMDebug.log("Relations -> " + gr.getRowCount() + " -> " + gr.getEncodedQuery());
while(gr.next()) {
if ( gr.getValue('external') == '1' )
continue;
this.relations.push(gr.getValue("sys_id"));
this.relationTypes[gr.getValue("sub_type")] = '1';
this.relationsObject[gr.getValue("sys_id")] = {
sys_id: gr.getValue("sys_id"),
number: gr.getValue("number"),
parent: gr.getValue("parent"),
child: gr.getValue("child"),
type: gr.getValue("type"),
sub_type: gr.getValue("sub_type")
};
}
},
getTasks: function() {
return this.tasksObject;
},
getTopTaskId: function() {
return this.topTaskId;
},
getTopPortfolioId: function() {
return this.topPortfolioId;
},
getTopProgramId: function() {
return this.topProgramId;
},
getRelations: function() {
return this.relationsObject;
},
getRelationTypes: function() {
var relTypes = [];
for ( var r in this.relationTypes ) {
relTypes.push(r);
}
if ( relTypes.length == 0 )
relTypes.push('None');
return relTypes;
},
isScheduleEntriesValid:function () {
var gr = new GlideRecord('pm_project');
gr.get(this.topTaskId);
if ( JSUtil.notNil(gr.getValue('schedule')) ) {
var scheduleEntriesGr = new GlideRecord("cmn_schedule_span");
scheduleEntriesGr.addQuery("schedule", gr.getValue('schedule'));
scheduleEntriesGr.query();
if(scheduleEntriesGr.getRowCount() > 0)
return true;
}
return false;
},
type: 'ProjectData'
};
Sys ID
b894054f9f31220088265bb0657fcfa4