Task is due by 5 and 1 days Notification

Lavanya Nagendr
Giga Guru

Hi All,

 

I have a requirement in which i need to send an Notification when an PTASK is not yet closed/updated in exactly 5 days before its due date, also for exactly 1 day before its due date.

 

Kindly provide your help on this.

 

Thanks,

Lavanya

1 ACCEPTED SOLUTION

Lavanya Nagendr
Giga Guru

I have finally made it to work, the below are my Scheduled Script for the Notification trigger!!

 

5-days Notification Remainder Scheduled Script Execution:  ( This will exclude Today and start count the days from tomorrow)

var now = new GlideDate();
now.addDays(8);
var seven = new GlideDate();
seven.addDays(7);
var gr = new GlideRecord('problem_task');
gr.addEncodedQuery('state!=157');
gr.addQuery('due_date','<=',now);
gr.addQuery('due_date','>',seven);
gr.query();
while(gr.next())
{
    var gdt = new GlideDateTime(gr.due_date);
    var day = gdt.getDayOfWeekUTC();
    if (day == 1 || day == 2 || day == 3 || day == 4 || day == 5){
		gs.eventQueue('event_name',gr);
	}
}

1-day Notification Remainder Scheduled Script Execution:  ( This will exclude Today and start count the days from tomorrow)

var one = new GlideDate();
one.addDays(2);
var now = new GlideDate();
now.addDays(1);
var gr = new GlideRecord('problem_task');
gr.addEncodedQuery('state!=157');
gr.addQuery('due_date','<=',one);
gr.addQuery('due_date','>',now);
gr.query();
while(gr.next())
{
    var gdt = new GlideDateTime(gr.due_date);
    var day = gdt.getDayOfWeekUTC();
    if (day == 1 || day == 2 || day == 3 || day == 4 || day == 5){
		gs.eventQueue('event_name',gr);
	}
}

 

Thanks!

Lavanya

 

 

View solution in original post

3 REPLIES 3

Sandeep Rajput
Tera Patron
Tera Patron

@Lavanya Nagendr You can achieve this either using a flow/workflow or using a scheduled job which runs daily and looks for this PTasks which are not closed updated in 5 days before its due date or 1 day before the due date.

I tried it below is my Scheduled Job and Notification. But it triggers 3times of same notification.

 

Scheduled Job:

Screenshot 2024-07-02 at 6.27.43 PM.png

var notif = new GlideRecord('problem_task');
notif.addEncodedQuery("due_dateRELATIVEGT@dayofweek@ahead@0^due_dateRELATIVELT@dayofweek@ahead@5^NQdue_dateRELATIVEGT@dayofweek@ahead@0^due_dateRELATIVELT@dayofweek@ahead@1");
notif.query();
while(notif.next()){
gs.eventQueue('problem_task.duedate.notify',notif);
}
 
Notification:
Screenshot 2024-07-02 at 6.28.53 PM.pngScreenshot 2024-07-02 at 6.29.02 PM.png
 
Thanks,
Lavanya

Lavanya Nagendr
Giga Guru

I have finally made it to work, the below are my Scheduled Script for the Notification trigger!!

 

5-days Notification Remainder Scheduled Script Execution:  ( This will exclude Today and start count the days from tomorrow)

var now = new GlideDate();
now.addDays(8);
var seven = new GlideDate();
seven.addDays(7);
var gr = new GlideRecord('problem_task');
gr.addEncodedQuery('state!=157');
gr.addQuery('due_date','<=',now);
gr.addQuery('due_date','>',seven);
gr.query();
while(gr.next())
{
    var gdt = new GlideDateTime(gr.due_date);
    var day = gdt.getDayOfWeekUTC();
    if (day == 1 || day == 2 || day == 3 || day == 4 || day == 5){
		gs.eventQueue('event_name',gr);
	}
}

1-day Notification Remainder Scheduled Script Execution:  ( This will exclude Today and start count the days from tomorrow)

var one = new GlideDate();
one.addDays(2);
var now = new GlideDate();
now.addDays(1);
var gr = new GlideRecord('problem_task');
gr.addEncodedQuery('state!=157');
gr.addQuery('due_date','<=',one);
gr.addQuery('due_date','>',now);
gr.query();
while(gr.next())
{
    var gdt = new GlideDateTime(gr.due_date);
    var day = gdt.getDayOfWeekUTC();
    if (day == 1 || day == 2 || day == 3 || day == 4 || day == 5){
		gs.eventQueue('event_name',gr);
	}
}

 

Thanks!

Lavanya