Name
global.PlannedTaskNotification
Description
A thin wrapper around PlannedTaskNotification table abstracts away low-level GlideRecord APIs for PlannedTaskNotification table
Script
var PlannedTaskNotification = Class.create();
PlannedTaskNotification.prototype = {
initialize: function(gr) {
this.notificationTable = "planned_task_notification";
this.gr = gr;
},
get: function (sysId) {
this.gr = new GlideRecord(this.notificationTable);
this.gr.get(sysId);
return this;
},
deleteRecord: function(workflow) {
this.gr.setWorkflow(workflow);
this.gr.deleteRecord();
},
isValid: function() {
return this.gr.isValidRecord();
},
getValue: function(col) {
return this.gr.getValue(col);
},
createNotification: function(params) {
var gr = new GlideRecord('planned_task_notification');
gr.source = params['source_id'];
gr.task = params['task_id'];
gr.shadow_task = params['shadow_task_id'];
gr.relation_applied = params['relation_applied'];
gr.message = params['msg'];
gr.setValue('start_date', params['start_date']);
gr.setValue('previous_start_date', params['previous_start_date']);
var id = gr.insert();
return new PlannedTaskNotification(gr);
},
isNewNotificationPending: function(params) {
gs.info("Into PlannedTaskNotification.isNewNotificationPending -> " + (new JSON()).encode(params));
var notification = this.getNewNotifications(params);
if ( notification.next() ) {
return { status: true, record: notification };
}
return { status: false };
},
getNewNotificationsForProject: function(projectId) {
var gr = new GlideRecord('planned_task_notification');
gr.addQuery('task.top_task', projectId);
gr.addQuery('state', 'new');
gr.orderByDesc('sys_created_on');
gr.query();
return gr;
},
getProcessedNotificationsForProject: function(projectId) {
var gr = new GlideRecord('planned_task_notification');
gr.addQuery('task.top_task', projectId);
gr.addQuery('state', 'processed');
gr.orderByDesc('sys_created_on');
gr.query();
return gr;
},
markAllHardNotificationsAsProcessed: function(projectId) {
var gr = new GlideRecord('planned_task_notification');
gr.addNotNullQuery('status');
gr.addQuery('task.top_task', projectId);
gr.addQuery('state', 'new');
gr.query();
gr.setValue('state', 'processed');
gr.updateMultiple();
},
getNewNotifications: function(params) {
gs.info("Into PlannedTaskNotification.getNewNotifications -> " + (new JSON()).encode(params));
var gr = new GlideRecord('planned_task_notification');
gr.addQuery('source', params['source_id']);
gr.addQuery('task', params['task_id']);
gr.addQuery('shadow_task', params['shadow_task_id']);
gr.addQuery('relation_applied', params['relation_applied']);
gr.addQuery('state', 'new');
gr.query();
gs.info('Notifications pending '+gr.getRowCount());
return gr;
},
markAsProcessed: function(notification) {
notification.setValue('state', 'processed');
notification.update();
},
acceptNotification: function() {
this.gr.setValue('status', 'accept');
//notification.setValue('state', 'processed');
this.gr.update();
},
clearNotifications: function(taskIds) {
gs.info("Into PlannedTaskNotification.clearNotifications -> " + (new JSON()).encode(taskIds));
if(JSUtil.notNil(taskIds) && taskIds.length > 0) {
var gr = new GlideRecord('planned_task_notification');
gr.addQuery('shadow_task', "IN", taskIds.join(","));
gr.query();
gs.info("clearNotifications -> " + gr.getRowCount() + " | " + gr.getEncodedQuery());
gr.deleteMultiple();
}
},
getProject: function() {
return this.gr.task.top_task.getRefRecord();
},
type: 'PlannedTaskNotification'
};
Sys ID
74198aea9f622200598a5bb0657fcf9e