To send notification in regular interval of time

RakshithaM
Tera Contributor

Hi All,

 

I have a requirement where i want to generate an email notification for regular interval of time for every 5 years until the ticket is closed. However the Date will remain same but the email must be getting triggered for every 5 years based on Date present in the field (Date can vary according to ticket creation).

Can someone please guide me how can i solve this.

 

Field type - Date

Field Name - Service Plan (u_service_plan)

 

Thanks in advance.

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

@RakshithaM 

you can use scheduled job for this flow which runs daily

what did you start with and where are you stuck?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Ankur Bawiskar
Tera Patron
Tera Patron

@RakshithaM 

something like this

var gr = new GlideRecord('your_table_name');
gr.addQuery('state', '!=', 'closed'); // Ensure the ticket is not closed
gr.query();
while (gr.next()) {
    var ticketDate = new GlideDateTime(gr.getValue('u_service_plan') + ' 00:00:00');
    var currentDate = new GlideDateTime();
    var fiveYearsAgo = currentDate.subtract(5 * 365 * 24 * 60 * 60 * 1000); // 5 years in milliseconds

    if (ticketDate.compareTo(fiveYearsAgo) <= 0) {
        gs.eventQueue('your_custom_event', gr, recipientEmail);
    }
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@RakshithaM 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Hi @Ankur Bawiskar , apologize

 

The above code is not working for me.

Below i have shared the scheduled job script for repeated interval of time and field name and its type. Can you please help me with this where i'm wrong.

Screenshot 2025-01-13 124613.pngScreenshot 2025-01-13 125137.png