reminder notification flow

Priyansh_98
Tera Guru

Hi,

 

I am having a requirement related to reminder notification...

once a ticket is in awaiting info state for 3 days, i have to send a reminder notification to user,

 

and after a 6 days also if the ticket is in awaiting info state.. i have to send a same reminder notification to the user.

 

and after 6th day i.e. on 7 th day i have to cancel that ticket.

 

i have created a scheduled job for that.. but some time it is not working

 

 

var grCase = new GlideRecord(' scoped custom table');
grCase.addEncodedQuery('active=true^state=18');
grCase.query();
while (grCase.next()) {
    var ticket_updated_time = new GlideDateTime(grCase.sys_updated_on);
    var today = new GlideDateTime();
    var duration_seconds = gs.dateDiff(ticket_updated_time, today, true);
    var duration_days = Math.round(duration_seconds / 60);
    gs.log('scoped job' + duration_days + 'case : '+grCase.number);
    if (duration_days == 5) {
        gs.eventQueue('gbs.case.awaiting.info.notification', grCase);
        gs.log('Reminder : 1 - reminder notification sent for this case using scheduled jobs : ' + grCase.number);
    }else if (duration_days == 10) {
        gs.eventQueue('gbs.case.awaiting.info.notification', grCase);
        gs.log('Reminder : 2 - reminder notification sent for this case using scheduled jobs : ' + grCase.number);
    }else if (duration_days > 10) {
        grCase.auto_close = true;
		gr.comments = 'test auto closure';
        grCase.state = 7;
        grCase.update();
        gs.eventQueue('gbs.case.cancelled', grCase);
        gs.log('case number : ' + grCase.number + ' cancelled by a scheduled script execution.');
    }
}

 

for testing i am executing it on 5 and 10 minutes.

but this is not working. can anyone help me with that.

4 REPLIES 4

johnfeist
Mega Sage
Mega Sage

Hi Priyansh_98,

 

One thing to consider is that because you are doing things in minutes, it is quite easy for objects to be at six or eleven minutes before you can run the job.  I would suggest changing the timing to hours (just change your divisor to 360) and manually/programatically set your dates for testing.

 

What I have done to address the requirement that you describe is to create a workflow that gets activated when your condition (waiting for info) and then handles things automatically.

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster

Hi @johnfeist & @Amitoj Wadhera ,

Thanks for your inputs..!!

I have tried workflow for this requirement and it worked.

 

 

 

Hi @Priyansh_98 ,

 

If you find my response helpful, please consider marking it as the 'Accepted Solution' and giving it a 'Helpful' rating. Your feedback not only supports the community but also encourages me to continue providing valuable assistance.

 

Regards,

Amitoj Wadhera
Kilo Sage

Hi @Priyansh_98 ,

 

Updated Script:

 

var grCase = new GlideRecord('scoped custom table');
grCase.addEncodedQuery('active=true^state=18');
grCase.query();

while (grCase.next()) {
    var ticket_updated_time = new GlideDateTime(grCase.sys_updated_on);
    var today = new GlideDateTime();
    var duration_seconds = gs.dateDiff(ticket_updated_time, today, true);
    var duration_days = duration_seconds / 86400;
    
    gs.log('scoped job ' + duration_days + ' case: ' + grCase.number);
    
    if (duration_days >= 3 && duration_days < 6) {
        gs.eventQueue('gbs.case.awaiting.info.notification', grCase);
        gs.log('Reminder: 3rd day reminder notification sent for this case: ' + grCase.number);
    } else if (duration_days >= 6 && duration_days < 7) {
        gs.eventQueue('gbs.case.awaiting.info.notification', grCase);
        gs.log('Reminder: 6th day reminder notification sent for this case: ' + grCase.number);
    } else if (duration_days >= 7) {
        grCase.state = 7;
        grCase.auto_close = true;
        grCase.comments = 'Auto-closed due to inactivity';
        grCase.update();
        gs.eventQueue('gbs.case.cancelled', grCase);
        gs.log('Case number: ' + grCase.number + ' auto-closed by a scheduled script execution.');
    }
}

 

If you find my response helpful, please consider marking it as the 'Accepted Solution' and giving it a 'Helpful' rating. Your feedback not only supports the community but also encourages me to continue providing valuable assistance.

 

Regards,

Amitoj