How to Notify Someone 1 Week Before End Date

msekla
Tera Contributor

Is there a way to send out an email notification to the "Requested By" person on the External Vendor Access request for like a week before the end date is due?  Just notifying that the access will be rescinded soon, giving the person a chance to change/extend the due date, if needed. A screenshot of the form I am talking about is attached.

32 REPLIES 32

I added/changed everything you told me to and now they email doesn't fire at all rather then firing instantly which was my first problem. I don't know why this is happening. Here's my code:

var gr = new GlideRecord('sc_req_item');
gr.addEncodedQuery('cat_item=72c5777a1b300a107640dc68b04bcbd1^stateNOT IN3,4,7');
gr.query();
while(gr.next()) {
 
    var startDate = new GlideDate();
var endDate = gr.variables.end_date;
    var gdt = new GlideDateTime(endDate);
//gs.info('Line number 6 ' + gdt);
    
    var dateDiff = GlideDateTime.subtract(startDate, gdt);
    var roundedDate = dateDiff.getRoundedDayPart();
 
 
//gs.info(' line number 12 ' + roundedDate);
 
    if (roundedDate == 6) {
        gs.eventQueue('expiry.notification', gr, '', '');
}
}

@msekla , to test this set the date to after 7 days including today and then go to scheduled job and click execute now,

 

Then go to emails log and check also check in event log whether event got triggered.

 

also test for other case aswell like set date to 10 days after or smtg and click execute now in scheduled job check whether email and event triggered or not (it should trigger in this case)

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

@swathisarang98 I think it works it's just extremely delayed but why does it fire the email twice at the same time? See the screenshot attached.

@msekla, could you please share your working schedule job script ? i will make the changes and will paste it here

 

Thanks

Swathi 

This is my current script and the rest of the other setting in the event and notification is the exact same as before in my previous screenshots I showed you. Here is my code:

var gr = new GlideRecord('sc_req_item');
gr.addEncodedQuery('cat_item=72c5777a1b300a107640dc68b04bcbd1^stateNOT IN3,4,7');
gr.query();
while(gr.next()) {
 
    var startDate = new GlideDate();
var endDate = gr.variables.end_date;
    var gdt = new GlideDateTime(endDate);
//gs.info('Line number 6 ' + gdt);
    
    var dateDiff = GlideDateTime.subtract(startDate, gdt);
    var roundedDate = dateDiff.getRoundedDayPart();
 
 
//gs.info(' line number 12 ' + roundedDate);
 
    if (roundedDate == 6) {
        gs.eventQueue('expiry.notification', gr, '', '');
}
}