Name
global.PushMessageQualifier
Description
A script that generates a list of push messages associated to a push application and from there generates a list of all notifications that use that push message
Script
var PushMessageQualifier = Class.create();
PushMessageQualifier.prototype = {
getNotifications: function(applicationSysId) {
var pushMsgIds = [];
var notifIds = [];
if (applicationSysId) {
pushMsgIds = this.getPushApplicationPushMessages(applicationSysId);
if (!pushMsgIds || pushMsgIds.length == 0 ) {
return 'sys_id=NULL';
}
else {
notifIds = this.getRawNotificationList(pushMsgIds);
}
}
if (notifIds.length == 0) {
return 'sys_id=NULL';
}
return 'sys_idIN' + notifIds;
},
getPushApplicationPushMessages: function(applicationSysId) {
// Basic input validation
if (!applicationSysId || applicationSysId === "") {
gs.error('Cannot find application because sys_id does not exist');
return [];
}
var applicationGR = new GlideRecord('sys_push_application');
if (!applicationGR.get(applicationSysId)) {
gs.error('Error generating push message ids, could not find application: ' +
applicationSysId);
return [];
}
var pushMsgIds = [];
var gr = new GlideRecord('sys_push_notif_msg');
var condition = gr.addQuery('push_app',applicationSysId);
condition.addOrCondition('push_app', applicationGR.getValue('parent_app'));
gr.query();
while (gr.next()) {
pushMsgIds.push(gr.getUniqueValue());
}
return pushMsgIds;
},
getRawNotificationList: function(pushMsgIds) {
var notifIds = [];
var gr = new GlideRecord('sysevent_email_action');
gr.addNotNullQuery('message_list');
gr.addActiveQuery();
gr.query();
while (gr.next()) {
var msgList = gr.getValue('message_list').split(',');
for ( i = 0; i < msgList.length; i++) {
for (x = 0; x < pushMsgIds.length; x++) {
if (msgList[i] == pushMsgIds[x]) {
notifIds.push(gr.getUniqueValue());
}
}
}
}
return notifIds;
},
type: 'PushMessageQualifier',
};
Sys ID
f033320a13539200a54fb8b12244b0b5