The CreatorCon Call for Content is officially open! Get started here.

Send email notification 5 business days before activity set triggers on employee start date.

chetanasand
Tera Contributor

Hello Everyone,

 

I am working on lifecycle event onboarding for new hire. I have created lifecycle event names onboarding and add activity set to it names Prepare, Day 1, Week 1 and so on. Prepare activity set triggers immediately when the HR case is created and Day 1 activity set triggers when it matches the employee start date mention in HR profile form. I have to send an email notification to manager 5 business days before day 1 activity set is triggered in the lifecycle event. 
Please help me the ways to set "when to send" condition while creating a notification so that emails triggers on correct time. 
Note: Table used while creating notification is sn_hr_le_case

1 ACCEPTED SOLUTION

Rafael Batistot
Kilo Patron

Hi @chetanasand 

 

ServiceNow notifications don’t have a native “X business days before” condition, but you can achieve this in a few ways:


To send email by ServiceNow, you need configure an event and link in your notification 

 

After that use a Scheduled Job to trigger this days 

  1. Create a Scheduled Job that runs daily (e.g., at midnight).
  2. In the script, query sn_hr_le_case records for onboarding lifecycle events:
    • Check the Employee Start Date (u_start_date or profile reference field).
    • Compare with today + 5 business days (you can use GlideDateTime.addBusinessDaysLocalTime(-5) if you’re on a recent release).
  3. If match found, trigger your email notification by:
    • Calling gs.eventQueue("your.custom.event", caseGR, managerSysId, "");
    • Configure a notification listening to that event.

 

 

If you found this response helpful, please mark it as Helpful. If it fully answered your question, consider marking it as Correct. Doing so helps other users find accurate and useful information more easily.

View solution in original post

3 REPLIES 3

Rafael Batistot
Kilo Patron

Hi @chetanasand 

 

ServiceNow notifications don’t have a native “X business days before” condition, but you can achieve this in a few ways:


To send email by ServiceNow, you need configure an event and link in your notification 

 

After that use a Scheduled Job to trigger this days 

  1. Create a Scheduled Job that runs daily (e.g., at midnight).
  2. In the script, query sn_hr_le_case records for onboarding lifecycle events:
    • Check the Employee Start Date (u_start_date or profile reference field).
    • Compare with today + 5 business days (you can use GlideDateTime.addBusinessDaysLocalTime(-5) if you’re on a recent release).
  3. If match found, trigger your email notification by:
    • Calling gs.eventQueue("your.custom.event", caseGR, managerSysId, "");
    • Configure a notification listening to that event.

 

 

If you found this response helpful, please mark it as Helpful. If it fully answered your question, consider marking it as Correct. Doing so helps other users find accurate and useful information more easily.

GlideFather
Tera Patron

Hi @chetanasand,

for scheduled triggering, you will need to change the notification to be sent when an event is fired or via flow

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


J Siva
Kilo Patron
Kilo Patron

Hi @chetanasand 
You need to use either a Scheduled Job or a Scheduled Flow to trigger notifications 5 business days before Day 1. Run the job daily and iterate over the records. If a record meets the condition, trigger the notification event. Try using the script below

function isTodayFiveBusinessDaysBefore(dueDateStr) {
    var dueDate = new GlideDateTime(dueDateStr);
    var today = new GlideDateTime();
    var tempDate = new GlideDateTime(dueDateStr);
    var businessDaysCount = 0;

    while (businessDaysCount < 5) {
		tempDate.addDaysLocalTime(-1);  // subtract 1 day
        var dayOfWeek = parseInt(tempDate.getDayOfWeekLocalTime(), 10); // 1 = Monday, 7 = Sunday

        if (dayOfWeek >= 1 && dayOfWeek <= 5) {
            businessDaysCount++;
        }
    }

    // Compare the calculated date with today's date
    return tempDate.getDate().getValue() == today.getDate().getValue();
}


var dueDate = '2025-08-25 00:00:00';
var isMatch = isTodayFiveBusinessDaysBefore(dueDate);
gs.info("Is today 5 business days before due date? " + isMatch);

Regards,
Siva