Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Notification is triggering multiple times

tulasi8
Tera Contributor

Hi Community,

 

In our current setup, the ServiceNow instance operates in the IST (Indian Standard Time) zone. A business rule was implemented to monitor incident creation for a specific domain. The rule triggers a notification when 25 incidents are created in a single day for a specific caller.

However, since our clients operate in the US/Eastern time zone, the notification logic needed to be aligned with their local time.

To address this, the business rule was updated to calculate the start and end of the day based on US/Eastern time, This ensures that the notification is triggered correctly when 25 incidents are created within the same calendar day as per US/Eastern time. But it is not working as expected. Sometimes it's triggering when 16th notification is created , sometimes its triggering when 25th notification is created . Sometimes it's triggering more than once in a single day .. 

 

Can anyone please help on this?

 

Conditions : after insert , domain is xyz, caller is xyz

Script :

(function executeRule(current, previous /*null when async*/ ) {

    var easternTZ = 'US/Eastern';

    // Get current time in Eastern Time
    var nowEastern = new GlideDateTime();
    nowEastern.setTimeZone(easternTZ);
   

    // Get date part only (yyyy-MM-dd)
    var easternDate = nowEastern.getLocalDate().toString();
   
    var startEastern = new GlideDateTime(easternDate + ' 00:00:00');
    startEastern.setTimeZone(easternTZ);
   

    var endEastern = new GlideDateTime(easternDate + ' 23:59:59');
    endEastern.setTimeZone(easternTZ);
    gs.print(endEastern);
    var startUTC = startEastern.getValue(); // UTC string
    var endUTC = endEastern.getValue();
   

    // Query incidents
    var gr = new GlideAggregate('incident');
    gr.addEncodedQuery('sys_domain=a028216e47ed51508b6b4537536d4383^sys_created_on>=' + startUTC + '^sys_created_on<=' + endUTC + '^caller_id=748b5c7f97071550d2ec73100153af73');
    gr.addAggregate('COUNT');
    gr.query();

    if (gr.next()) {
        var count = parseInt(gr.getAggregate('COUNT'), 10);
       
        if (count == 25) {
            gs.eventQueue('it.checkmate.incident.limit.reached', current);
        }
    }
   

})(current, previous);
 
 
Regards,
Prasanna.
12 REPLIES 12

@tulasi8 

try the latest script I shared.

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

@Ankur Bawiskar Both the previous script and the latest script are working as expected in the development environment. The latest script also successfully triggers the notification at the 25th incident. However, we need to ensure that this behavior will be consistent in the production environment. Could you please confirm? 

tulasi8
Tera Contributor

@Ankur Bawiskar The previous script works correctly in the lower environment; however, in production, its behavior is inconsistent. Sometimes the notification triggers on the 25th incident, other times on the 16th, and occasionally it triggers twice. This should not be happening. 

tulasi8
Tera Contributor

@Ankur Bawiskar please help on this 

@tulasi8 

unless you replicate that issue in lower instance you can't debug.

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