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

mhegde1
Kilo Sage

Hi @msekla ,

 

Try with Below piece of code in scheduled job and also create Event--> notification.

 

 

 

sendEmail();

function sendEmail() {
    try {
        var weeklygr = new GlideRecord('table_name');
        weeklygr.addEncodedQuery('');     // if any particular filter needed u can add this otherwise skip this addEncodedQuery
        weeklygr.query();
        while (weeklygr.next()) {
            var gdt = new GlideDateTime(weeklygr.varaibles.end_date);
            var nowTime = new GlideDateTime();                          //current date
            var duration = GlideDateTime.subtract(nowTime, gdt);
            var days = duration.getDayPart();
			//gs.log(days);
            if (days == 7) {
                gs.eventQueue("Event Name", weeklygr,parm1 , parm2 );
            }
        }
    } catch (ex) {
        gs.info('Exception' + ex);
    }
}

 

 

 

thanks,

msekla
Tera Contributor

@mhegde1 What would I have to change in this code that special to my form for this to work as intended? Is there a backend field in here that I should change or is this code good? I also change the addEncodedQuery:

sendEmail();

function sendEmail() {
try {
var weeklygr = new GlideRecord('table_name');
weeklygr.addEncodedQuery('cat_item=72c5777a1b300a107640dc68b04bcbd1^stateNOT IN3,4,7');
weeklygr.query();
while (weeklygr.next()) {
var gdt = new GlideDateTime(weeklygr.varaibles.end_date);
var nowTime = new GlideDateTime();
var duration = GlideDateTime.subtract(nowTime, gdt);
var days = duration.getDayPart();
if (days == 7) {
gs.eventQueue("Event Name", weeklygr,parm1 , parm2 );
}
}
} catch (ex) {
gs.info('Exception' + ex);
}
}

Hi @msekla ,

 

Need to change the 

1) Table Name

2) Event name and Parameters (to whom should the email go) , if not in parameters, mention in notification. In this case you modify as this - gs.eventQueue("Event Name", weeklygr); in the above code.

3) If your sending the notification one particular item then you can No need to use While (while (weeklygr.next()) : try with If

4) Try to log "days" and check in "system logs" to see if you are getting correct date difference. 

//gs.log(days);

5) check whether event is triggered in "event logs" .

 

Follow the steps mentioned by for testing  @swathisarang98 it should work.

 

thanks,