Use PDIs? Take our 5-minute survey to help shape the PDI roadmap.

GroupingProduceGroupMainAlertHook - script include not working as expected

sgchandran
Tera Contributor

Hi , 

 

I have referred the documentation :

 https://www.servicenow.com/docs/r/it-operations-management/event-management/alert-group-use-cases.ht...

 

and configured the script accordingly in a way to return the oldest alert created as main alert for tag based clustering , but still its not accepting my change as grouping logic and following tag based clustering's grouping logic that is 

alert 1 

alert 2 

alert 3 (created on its own and alert 1 ,2 will become 3's child)

 

below is the script i used :

 

var GroupingProduceGroupMainAlertHook = Class.create();
GroupingProduceGroupMainAlertHook.prototype = {
    initialize: function() {},

    getMainAlert: function(groupAlertIDs) {
              if (!groupAlertIDs) {
         
            return null;
        }

        var gr = new GlideRecord('em_alert');
        gr.addQuery('sys_id', 'IN', groupAlertIDs);
        gr.orderBy('sys_created_on'); // oldest first
        gr.setLimit( 1 );
 
        gr.query();

        if (gr.next()) {
            return gr;
        }
        return null;
    },

    type: 'GroupingProduceGroupMainAlertHook'
};

 

 

 

1 REPLY 1

Rafael Batistot
Kilo Patron

Hi @sgchandran 

 

Return the alert's sys_id string instead of the full GlideRecord object.


When getMainAlert receives an object, the platform ignores it and falls back to its default tag-based clustering logic.

  • Before: return gr; (GlideRecord)
  • After: return grAlert.getValue('sys_id'); (String)

 

var GroupingProduceGroupMainAlertHook = Class.create();
GroupingProduceGroupMainAlertHook.prototype = {
initialize: function() {},

getMainAlert: function(groupAlertIDs) {
var alertSysId = "";
var grAlert = null;

return !groupAlertIDs ? "" : (function() {
grAlert = new GlideRecord('em_alert');
grAlert.addQuery('sys_id', 'IN', groupAlertIDs);
grAlert.orderBy('sys_created_on');
grAlert.setLimit(1);
grAlert.query();

return grAlert.next() ? grAlert.getValue('sys_id') : "";
})();
},

type: 'GroupingProduceGroupMainAlertHook'
};

 

If this response was helpful, please mark it as Helpful and, if applicable, as Correct.
This helps other users find accurate and useful information more easily