group alerts if there are 3 alerts if not dont group them

AnimeshP_96
Kilo Sage

requirement is if 3 alerts is created in servicenow , group them which is working but now what is happening is 3 alerts are created but this rule is not matching and showing some different rule in activites under work notes ,some other rule is taking precendence. ..so now if 4 alerts re created it should not group it 

(function findCorrelatedAlerts(currentAlert) {

    var result = {};
    var table = "em_alert";
    //var cnt;
    var storeID = [];
    //var childalerts = [];
    var parent = [];
    var alertGr = new GlideRecord(table);
    alertGr.addNullQuery("parent");
    alertGr.orderBy("sys_created_on");
    alertGr.setLimit(3);
    alertGr.query();
    while (alertGr.next()) {
        gs.info("this is li3ne 13 from me");
        storeID.push(alertGr.getUniqueValue());

    }


    if (storeID.length === 3) {
        gs.info("this is2222229833 ");
        parent = currentAlert.sys_id;
    }
    gs.info("this is2379863 " + parent);
    result = {
        'parent': [String(currentAlert.sys_id)]
    };

    return JSON.stringify(result);

})(currentAlert);

pls can someone help me where i am going wrong..

in the below picture it is creating a new alert instead of making 607 as parent which is expected
AnimeshP_96_0-1762176452983.png

AnimeshP_96_0-1762240364470.png

 

 


Please accept the solution /mark this response as correct or helpful if it assisted you with your question.




Regards,
Animesh
1 ACCEPTED SOLUTION

so first log :   gs.info("this is li3ne 13 from me");  this is printed 6 times in log table but it should be 3 becuase setlimit(3) is provided in the script


Please accept the solution /mark this response as correct or helpful if it assisted you with your question.




Regards,
Animesh

View solution in original post

11 REPLIES 11

@AnimeshP_96 

sorry I didn't get the time

Also I don't have event management installed on my PDI

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

AnimeshP_96
Kilo Sage

grouping is happening but manual, if you see group column, it should be tag cluster, but its not working using script logic. @TejasSN_LogicX @Ankur Bawiskar  let me know if any luck 
also m using alert corealtion rule  table =em_alertCapture_1.PNG


Please accept the solution /mark this response as correct or helpful if it assisted you with your question.




Regards,
Animesh