We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Weekly approval reminders notification

Utkarsha
Tera Contributor

Hello all,

I need to configure email notifications which will be triggered after 7,14,21  days. The final reminder is the one post completing 21days. I am using event, notification, scheduled script execution, email script

Could anyone please help me out with the scripting part here?

Any kind of help would be highly appreciated.

Thank you 

.

1 ACCEPTED SOLUTION

Danish Bhairag2
Tera Sage

Hi @Utkarsha  ,

 

Please use the below scheduled script to trigger the notifications.

 

 

 

 

 

var gr = new GlideRecord('sysapproval_approver');
gr.addEncodedQuery('sysapproval.numberSTARTSWITHINC^state=requested'); // assuming the reminder needs to be sent for Incident records, please modify the query based on your requirement
gr.query();
while(gr.next()){
    var createdDate = new GlideDateTime(gr.sys_created_on);
    var today = new GlideDateTime();
    var noOfDays = GlideDateTime.subtract(today, createdDate).getDayPart();

    if (noOfDays == 7 || noOfDays == 14 || noOfDays == 21) {
        gs.eventQueue('reminder_email', gr, gr.approver,noOfDays);
    }else{
        //
    }
}

 

 

 

 

 

You can write a Email Script where u can use event.parm2 to indicate the reminder email whether its 1/2/final reminder. You can use same email for triggering all the reminder notifications.

 

Please mark my answer helpful & accepted if it helps you resolve your query.

 

Thanks,

Danish

View solution in original post

3 REPLIES 3

Anand Kumar P
Tera Patron

Hi @Utkarsha  ,

Use below script in schedule job runs daily  and change table name and encoded query and event names accordingly.

notifications.

var gr = new GlideRecord('incident ');
gr.addEncodedQuery(‘add_your_query  according to your requirment'); 
gr.query();
if (gr.next()) {
var createdDate = new GlideDateTime(gr.sys_created_on);
var today = new GlideDateTime();
var daysSinceCreation = GlideDateTime.subtract(today, createdDate).getDayPart();

if (daysSinceCreation == 7) {
// Trigger the 7-day notification
gs.eventQueue('notification_trigger_event', gr, gr.caller_id);
} else if (daysSinceCreation == 14) {
// Trigger the 14-day notification
gs.eventQueue('notification_trigger_event', gr, gr.caller_id);
} else if (daysSinceCreation == 21) {
// Trigger the 21-day notification
gs.eventQueue('notification_trigger_event', gr, gr.caller_id);
} 
}

Please mark helpful and solution proposed if it works.

 

Thanks,

Anand

Danish Bhairag2
Tera Sage

Hi @Utkarsha  ,

 

Please use the below scheduled script to trigger the notifications.

 

 

 

 

 

var gr = new GlideRecord('sysapproval_approver');
gr.addEncodedQuery('sysapproval.numberSTARTSWITHINC^state=requested'); // assuming the reminder needs to be sent for Incident records, please modify the query based on your requirement
gr.query();
while(gr.next()){
    var createdDate = new GlideDateTime(gr.sys_created_on);
    var today = new GlideDateTime();
    var noOfDays = GlideDateTime.subtract(today, createdDate).getDayPart();

    if (noOfDays == 7 || noOfDays == 14 || noOfDays == 21) {
        gs.eventQueue('reminder_email', gr, gr.approver,noOfDays);
    }else{
        //
    }
}

 

 

 

 

 

You can write a Email Script where u can use event.parm2 to indicate the reminder email whether its 1/2/final reminder. You can use same email for triggering all the reminder notifications.

 

Please mark my answer helpful & accepted if it helps you resolve your query.

 

Thanks,

Danish

Riya Verma
Kilo Sage

Hi @Anand Kumar P ,

 

 

Hope you are doing great.

 

o configure email notifications triggered after 7, 14, and 21 days, with the final reminder sent after completing 21 days in ServiceNow, you can follow these steps:

  1. In your ServiceNow instance, navigate to "System Notification" > "Notifications."  Create a new notification for the email you want to send. Configure the email content, subject, and recipient as needed
  2. Create an Event:

    • Go to "System Policy" > "Events."
    • Create a new event that will trigger this notification. Give it a meaningful name.
    • Set the "Table" to the table you're tracking, such as "Incident" or "Task."
    • Define the conditions for when this event should be fired. For example, you might use a condition like "incident_state = 'In Progress'."
  3. Create a Scheduled Script Execution:

    • In ServiceNow, go to "System Scheduler" > "Scheduled Script Execution."Create a new schedule for your script. Specify the frequency, such as daily.
    • In the script field, write a script that checks the records in your target table.
    • Calculate the time difference between the current date and the date the record was created.
    • If the difference is 7, 14, or 21 days, trigger the event you created earlier.

simplified example of a script to get you started:

// Assuming 'current' represents the record being checked
var createdDate = new GlideDateTime(current.sys_created_on);
var currentDate = new GlideDateTime();
var daysSinceCreated = GlideDateTime.subtract(currentDate, createdDate).getDayPart();

if (daysSinceCreated == 7 || daysSinceCreated == 14 || daysSinceCreated == 21) {
    gs.eventQueue("your_custom_event_name", current, current.user); // Trigger the event
}

 

 

 
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma