Survey Reminder on the 5th day

charri04
Tera Expert

Good evening,

Just a quick question. I need to send an email reminder on the 5th day for suppliers who have not taken their survey. 

Could someone tell me if the below code looks okay?

 

sendNotification();

function sendNotification() {

try {
var query = 'sys_created_onRELATIVELT@dayofweek@ago@5';
var gr = new GlideRecord('asmt_assessment_instance');
gr.addEncodedQuery('metric_type.nameLIKESupplier Case Satisfaction Survey^stateINready,wip^userISNOTEMPTY');
gr.query();
while (gr.next()) {
gs.eventQueue('sn_supplier.case.reminder_5days', gr, gr.user, '');
}
} catch (ex) {
gs.info(ex);
}

}


Best regards,

 

 

charri04

2 ACCEPTED SOLUTIONS

Mark Manders
Mega Patron

Why a scheduled job? 

Just create a flow on survey creation. Add the flow logic 'wait for a duration of time' and set that to 5 days. do a check to see if the survey is still open and if so, use the 'send notification' action. No need for scripting at all.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

View solution in original post

Community Alums
Not applicable

Hi @charri04 ,

Please try below code this will works for you

// var query = 'sys_created_onRELATIVELT@dayofweek@ago@5';
var gr = new GlideRecord('asmt_assessment_instance');
gr.addEncodedQuery('metric_type.nameLIKESupplier Case Satisfaction Survey^stateINready,wip^userISNOTEMPTY');
gr.query();
while (gr.next()) {
    var createddate = gr.sys_created_on;
    var createdDateGDT = new GlideDateTime(createddate);
    var currentDate = new GlideDateTime();
    var dur = GlideDateTime.subtract(createdDateGDT, currentDate); // Difference between gdt1 and gdt2
    var daysCount = dur.getDayPart()
    gs.info(daysCount);

    if (daysCount == 5) {
        gs.print("1 = " + createdDateGDT + " 2 = " + currentDate);
        gs.eventQueue('sn_supplier.case.reminder_5days', gr, gr.user, '');
    }

}

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak

View solution in original post

4 REPLIES 4

Mark Manders
Mega Patron

Why a scheduled job? 

Just create a flow on survey creation. Add the flow logic 'wait for a duration of time' and set that to 5 days. do a check to see if the survey is still open and if so, use the 'send notification' action. No need for scripting at all.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Thanks @Mark Manders for responding!

It took a bit of trial and error but decided to go with the flow instead of scripting.

 

Best regards,

 

 

Corey

Community Alums
Not applicable

Hi @charri04 ,

Please try below code this will works for you

// var query = 'sys_created_onRELATIVELT@dayofweek@ago@5';
var gr = new GlideRecord('asmt_assessment_instance');
gr.addEncodedQuery('metric_type.nameLIKESupplier Case Satisfaction Survey^stateINready,wip^userISNOTEMPTY');
gr.query();
while (gr.next()) {
    var createddate = gr.sys_created_on;
    var createdDateGDT = new GlideDateTime(createddate);
    var currentDate = new GlideDateTime();
    var dur = GlideDateTime.subtract(createdDateGDT, currentDate); // Difference between gdt1 and gdt2
    var daysCount = dur.getDayPart()
    gs.info(daysCount);

    if (daysCount == 5) {
        gs.print("1 = " + createdDateGDT + " 2 = " + currentDate);
        gs.eventQueue('sn_supplier.case.reminder_5days', gr, gr.user, '');
    }

}

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak

Hi @Community Alums !

Thanks for responding and helping me out with the code. I did try the code and it worked! I decided to go with flow designer to make it easier on the client that I'm currently working with.

 

Best regards,

 

 

Corey