The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How to trigger alerts at 50%, 75% and 100% of Change Window in Change Request?

Mahalakshmi Rav
Tera Contributor

Hi everyone,

I’m trying to send alerts when a Change Request reaches 50%, 75% and 100% of its planned time window. But my Business Rule (on update) is not triggering for any of the events

 

What I want to do:

  • Alert 1 – 50% time reached: When the Change Request is fully approved And 50% of the time between planned start_date and end_date is completed
  • Alert 2 – 75% time reached : Same condition as above but at 75% of the time
  • Alert 3 – End Time reached: When the planned end_date/time is reached and Change is still in Scheduled or Implement state (not moved to Review)


My current code (Business Rule - Update):

(function executeRule(current, previous /*null when async*/) {
   
    // Get current time
    var currentTime = new GlideDateTime();

    // Getting planned start and end dates from the change request
    var startDate = new GlideDateTime(current.getValue('start_date'));
    var endDate = new GlideDateTime(current.getValue('end_date'));

    // Calculate the full duration in milliseconds
    var milliSecs = endDate.getNumericValue() - startDate.getNumericValue();

    // Now taking 50% and 75% of the total time
    var fiftyPercentMillis = milliSecs * 0.5;
    var seventyFivePercentMillis = milliSecs * 0.75;

    // Adding that 50% time to start date to get exact 50% time
    var fiftyPercent = new GlideDateTime(startDate);
    fiftyPercent.add(fiftyPercentMillis);

    // Same for 75%
    var seventyFivePercent = new GlideDateTime(startDate);
    seventyFivePercent.add(seventyFivePercentMillis);

    // If current time is equal or after 50% time, then send 50% event else trigger the 75% event

    if (now.onOrAfter(fiftyPercent)){
        gs.eventQueue('50%_planned_start_and_end_date_notification', current);
    }
    else if (now.onOrAfter(seventyFivePercent)){
        gs.eventQueue('75%_planned_start_and_end_date_notification', current);
    }
})(current, previous);

MahalakshmiRav_1-1754343269336.png

MahalakshmiRav_2-1754343527621.png

 

The script is not sending any event, even when I update the record after the 50% ,75% or 100% time has passed. Nothing gets triggered.

is there anything wrong with my BR approach or is there a better way to achieve this?

1 REPLY 1

J Siva
Tera Sage

Hi @Mahalakshmi Rav 

I don’t think this requirement can be met using a Business Rule.

Instead, try using Flow Designer.

There’s also a workaround: create an internal SLA definition record along with a custom SLA flow. This is likely the simplest approach to fulfill your requirement. - Consider this approach only if you don’t find a better alternative.

Regards,
Siva